using Air.Model; using Air.Model.AirAdminViewModel; using Mini.Model; using Mini.Model.Entity; using System; using System.Collections.Generic; using System.Linq; namespace Mini.Services.Bas { public class BasModuleMenuService : IBasModuleMenuService { private readonly IAdminRepository _Bas_ModuleMenuRepository; public BasModuleMenuService(IAdminRepository Bas_ModuleMenuRepository) { this._Bas_ModuleMenuRepository = Bas_ModuleMenuRepository; } public void Create(Bas_ModuleMenuModel model) { var info = new Bas_ModuleMenu() { ModuleMenuId = model.ModuleMenuId, MName = model.MName, RightId = model.RightId, ImageUrl = model.ImageUrl, SortId = model.SortId, CTime = model.CTime }; _Bas_ModuleMenuRepository.Add(info); } public void Delete(Bas_ModuleMenuModel model) { var info = _Bas_ModuleMenuRepository.Get(p => p.ModuleMenuId == model.ModuleMenuId); if (info != null) { _Bas_ModuleMenuRepository.Delete(info); } } public Bas_ModuleMenuModel Get(int Id) { var model = _Bas_ModuleMenuRepository.Get(p => p.ModuleMenuId == Id); var info = new Bas_ModuleMenuModel() { ModuleMenuId = model.ModuleMenuId, MName = model.MName, RightId = model.RightId, ImageUrl = model.ImageUrl, SortId = model.SortId, CTime = model.CTime }; return info; } public IList GetList() { return _Bas_ModuleMenuRepository.GetList() .Select(p => new Bas_ModuleMenuModel() { ModuleMenuId = p.ModuleMenuId, MName = p.MName, RightId = p.RightId, ImageUrl = p.ImageUrl, SortId = p.SortId, CTime = p.CTime }) .ToList(); } public void Sort(string ids, string sortIds) { IList list = new List(); var idStr = ids.Split(','); var sortStr = sortIds.Split(','); for (int i = 0; i < idStr.Length; i++) { var id = Convert.ToInt32(idStr[i]); var sortId = Convert.ToInt32(sortStr[i]); var entry = _Bas_ModuleMenuRepository.Get(p => p.ModuleMenuId == id); if (entry == null) continue; entry.SortId = sortId; list.Add(entry); } _Bas_ModuleMenuRepository.AddList(list); } public void Update(Bas_ModuleMenuModel model) { var info = _Bas_ModuleMenuRepository.Get(p => p.ModuleMenuId == model.ModuleMenuId); if (info != null) { info.MName = model.MName; info.RightId = model.RightId; info.ImageUrl = model.ImageUrl; info.SortId = model.SortId; _Bas_ModuleMenuRepository.Update(info); } } } }