public List <ItemDTO> GetListItem() { using (db = new MobileEntities()) { return(DALUtilitiesMethod.ItemDTOList(db.ITEMs.ToList())); } }
public List <SubCategoryDTO> GetListSubCategoryWhenIdCategory(int _pIdCategory) { using (db = new MobileEntities()) { return(DALUtilitiesMethod.SubCategoryDTOList(db.SUBCATEGORies.Where(n => n.CategoryId == _pIdCategory).ToList())); } }
public List <UserDTO> GetListUser() { using (db = new MobileEntities()) { return(DALUtilitiesMethod.UserDTOList(db.USERs.ToList())); } }
public List <SubCategoryDTO> GetListSubCategory() { using (db = new MobileEntities()) { return(DALUtilitiesMethod.SubCategoryDTOList(db.SUBCATEGORies.ToList())); } }
public bool EditItem(ItemDTO pItemDTO) { using (db = new MobileEntities()) { ITEM item = db.ITEMs.SingleOrDefault(n => n.Id == pItemDTO.Id); if (item == null) { return(false); } try { item.Id = pItemDTO.Id; item.Name = pItemDTO.Name; item.Ram = pItemDTO.Ram; item.Pin = pItemDTO.Pin; item.Camera = pItemDTO.Camera; item.Cpu = pItemDTO.Cpu; item.Price = pItemDTO.Price; item.Image = pItemDTO.Image; item.Quantity = pItemDTO.Quantity; db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public string SelectPictureName(int pIdItem) { using (db = new MobileEntities()) { ITEM item = db.ITEMs.SingleOrDefault(n => n.Id == pIdItem); if (item != null) { return(item.Image); } return(""); } }
public bool CanDeleteSubCategory(int pSubCatID) { using (db = new MobileEntities()) { SUBCATEGORY subCategory = db.SUBCATEGORies.SingleOrDefault(n => n.Id == pSubCatID); // Nếu tồn tại sách thuộc category thì không thể xóa if (subCategory.ITEMs.Count > 0) { return(false); } return(true); } }
public bool ExisCattName(string pCatName, int pCatID) { using (db = new MobileEntities()) { var n = db.CATEGORies.SingleOrDefault(p => p.Name.Equals(pCatName) && p.Id != pCatID); if (n != null) { return(false); } else { return(true); } } }
public int SelectIdCategory(string pCategoryName) { using (db = new MobileEntities()) { CATEGORY category = db.CATEGORies.SingleOrDefault(n => n.Name == pCategoryName); if (category != null) { return(category.Id); } else { return(-1); } } }
public bool ExisSubName(string pSubName, int pSubID, int pCatId) { using (db = new MobileEntities()) { var n = db.SUBCATEGORies.SingleOrDefault(p => p.Name.Equals(pSubName) && p.CategoryId == pCatId && p.Id != pSubID); if (n != null) { return(false); } else { return(true); } } }
public bool CheckAccount(string pAccountName, string pPassword) { using (db = new MobileEntities()) { var query = db.ACCOUNTs.SingleOrDefault(p => p.AccountName.Equals(pAccountName) && p.Password.Equals(pPassword) && p.Level == 1); if (query != null) { return(true); } else { return(false); } } }
public string SelectNameItem(int pItemID) { using (db = new MobileEntities()) { ITEM item = db.ITEMs.SingleOrDefault(n => n.Id == pItemID); if (item != null) { return(item.Name); } else { return(""); } } }
public bool ExisItemName(string pItemName, int pItemID) { using (db = new MobileEntities()) { var n = db.ITEMs.SingleOrDefault(p => p.Name.Equals(pItemName) && p.Id != pItemID); if (n != null) { return(false); } else { return(true); } } }
public string SelectNameCategory(int pCategoryID) { using (db = new MobileEntities()) { CATEGORY category = db.CATEGORies.SingleOrDefault(n => n.Id == pCategoryID); if (category != null) { return(category.Name); } else { return(""); } } }
public bool AddItem(ItemDTO pItemDTO) { using (db = new MobileEntities()) { ITEM item = DALUtilitiesMethod.ToItem(pItemDTO); try { db.ITEMs.Add(item); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool AddCategory(CategoryDTO pCategoryDTO) { using (db = new MobileEntities()) { CATEGORY category = DALUtilitiesMethod.ToCategory(pCategoryDTO); try { db.CATEGORies.Add(category); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool AddSubCategory(SubCategoryDTO pSubCategoryDTO) { using (db = new MobileEntities()) { SUBCATEGORY subCategory = DALUtilitiesMethod.ToSubCategory(pSubCategoryDTO); try { db.SUBCATEGORies.Add(subCategory); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool DeleteSubCategory(int pSubCategoryID) { using (db = new MobileEntities()) { SUBCATEGORY subCategory = db.SUBCATEGORies.SingleOrDefault(n => n.Id == pSubCategoryID); try { db.SUBCATEGORies.Remove(subCategory); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool CanDeleteCategory(int pCatID) { using (db = new MobileEntities()) { CATEGORY category = db.CATEGORies.SingleOrDefault(n => n.Id == pCatID); List <SUBCATEGORY> sub = db.SUBCATEGORies.Where(m => m.CategoryId == category.Id).ToList(); // Nếu tồn tại sách thuộc category thì không thể xóa if (category.ITEMs.Count > 0) { return(false); } else if (sub.Count > 0) { return(false); } return(true); } }
public List <ItemDTO> GetListItemNoRelationItemCategory(int _pCategoryId) { using (db = new MobileEntities()) { List <ITEM> _lstItem = new List <ITEM>(); List <ItemDTO> lstItemDTO = new List <ItemDTO>(); CATEGORY category = db.CATEGORies.SingleOrDefault(n => n.Id == _pCategoryId); if (category == null) { return(null); } else { if (category.ITEMs.Count == 0) { _lstItem = db.ITEMs.ToList(); } else { foreach (var item in category.ITEMs) { _lstItem = db.ITEMs.Where(n => n.Id != item.Id).ToList(); //for (int i = 0; i < _lstItem.Count; i++) //{ // if (_lstItem[i].Id == item.Id) // { // ListItem.Add(_lstItem[i]); // } //} } } foreach (var k in _lstItem) { ItemDTO itemDTO = new ItemDTO(); itemDTO.Id = k.Id; lstItemDTO.Add(itemDTO); } return(lstItemDTO); } } }
public bool DeleteItem(int pItemID) { using (db = new MobileEntities()) { ITEM item = db.ITEMs.SingleOrDefault(n => n.Id == pItemID); try { item.CATEGORies.Clear(); item.SUBCATEGORies.Clear(); db.ITEMs.Remove(item); db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool EditCategory(CategoryDTO pCategoryDTO) { using (db = new MobileEntities()) { CATEGORY category = db.CATEGORies.SingleOrDefault(n => n.Id == pCategoryDTO.Id); if (category == null) { return(false); } try { category.Name = pCategoryDTO.Name; db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public List <ItemDTO> GetListItemWhenCategoryId(int _pCategoryId) { using (db = new MobileEntities()) { List <ItemDTO> lstItemDTO = new List <ItemDTO>(); CATEGORY category = db.CATEGORies.SingleOrDefault(n => n.Id == _pCategoryId); if (category == null) { return(null); } else { foreach (var item in category.ITEMs) { ItemDTO itemDTO = new ItemDTO(); itemDTO.Id = item.Id; lstItemDTO.Add(itemDTO); } } return(lstItemDTO); } }
public bool EditSubCategory(SubCategoryDTO pSubCategoryDTO) { using (db = new MobileEntities()) { SUBCATEGORY subCategory = db.SUBCATEGORies.SingleOrDefault(n => n.Id == pSubCategoryDTO.Id); if (subCategory == null) { return(false); } try { subCategory.CategoryId = pSubCategoryDTO.CategoryId; subCategory.Name = pSubCategoryDTO.Name; db.SaveChanges(); return(true); } catch (Exception) { return(false); } } }