// tạo hàm xóa public Response <VendorModel> Delete(int iVendorID) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpVendor = unitOfWorkStore.GetRepository <Vendor>(); Vendor vendorEntity = rpVendor.GetById(iVendorID); rpVendor.Delete(vendorEntity); //unitOfWorkStore.Save(); if (unitOfWorkStore.Save() >= 1) { return(new Response <VendorModel>((int)StatusResponses.Success, MessageResConst.Success, null)); } else { return(new Response <VendorModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, null)); } } } catch (Exception ex) { return(new Response <VendorModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <BranchModel> UpdateBranch(BranchModel BranchModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpBranch = unitOfWorkStore.GetRepository <Branch>(); Branch BranchEntity = rpBranch.GetById(BranchModel.Branch_ID); BranchEntity.Branch_ID = BranchModel.Branch_ID; BranchEntity.Branch_Name = BranchModel.Branch_Name; BranchEntity.Region = BranchModel.Region; BranchEntity.CommuneWard = BranchModel.CommuneWard; BranchEntity.Email = BranchModel.Email; BranchEntity.Phone = BranchModel.Phone; BranchEntity.Address = BranchModel.Address; rpBranch.Update(BranchEntity); if (unitOfWorkStore.Save() >= 1) { BranchModel.Branch_Name = BranchEntity.Branch_Name; return(new Response <BranchModel>((int)StatusResponses.Success, MessageResConst.Success, BranchModel)); } else { return(new Response <BranchModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, BranchModel)); } } } catch (Exception ex) { return(new Response <BranchModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <CountryModel> UpdateCountry(CountryModel CountryModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpCountry = unitOfWorkStore.GetRepository <Country>(); Country CountryEntity = rpCountry.GetById(CountryModel.Country_ID); CountryEntity.Country_ID = CountryModel.Country_ID; CountryEntity.Name = CountryModel.Name; rpCountry.Update(CountryEntity); if (unitOfWorkStore.Save() >= 1) { CountryModel.Name = CountryEntity.Name; return(new Response <CountryModel>((int)StatusResponses.Success, MessageResConst.Success, CountryModel)); } else { return(new Response <CountryModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, CountryModel)); } } } catch (Exception ex) { return(new Response <CountryModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <ImageModel> InsertImage(ImageModel ImageModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpImage = unitOfWorkStore.GetRepository <Image>(); Image ImageEntity = new Image(); ImageEntity.Image_ID = ImageModel.Image_ID; ImageEntity.Name = ImageModel.Name; ImageEntity.Url = ImageModel.Url; rpImage.Add(ImageEntity); if (unitOfWorkStore.Save() >= 1) { ImageModel.Name = ImageEntity.Name; return(new Response <ImageModel>((int)StatusResponses.Success, MessageResConst.Success, ImageModel)); } else { return(new Response <ImageModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, ImageModel)); } } } catch (Exception ex) { return(new Response <ImageModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <Item_SizeModel> UpdateItem_Size(Item_SizeModel Item_SizeModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpItem_Size = unitOfWorkStore.GetRepository <Item_Size>(); Item_Size Item_SizeEntity = rpItem_Size.GetById(Item_SizeModel.Item_Size1); Item_SizeEntity.Name = Item_SizeModel.Name; rpItem_Size.Update(Item_SizeEntity); if (unitOfWorkStore.Save() >= 1) { Item_SizeModel.Name = Item_SizeEntity.Name; return(new Response <Item_SizeModel>((int)StatusResponses.Success, MessageResConst.Success, Item_SizeModel)); } else { return(new Response <Item_SizeModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, Item_SizeModel)); } } } catch (Exception ex) { return(new Response <Item_SizeModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <EmployeeModel> UpdateEmployee(EmployeeModel EmployeeModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpEmployee = unitOfWorkStore.GetRepository <Employee>(); Employee EmployeeEntity = rpEmployee.GetById(EmployeeModel.Employee_ID); EmployeeEntity.Employee_ID = EmployeeModel.Employee_ID; EmployeeEntity.Employee_Code = EmployeeModel.Employee_Code; EmployeeEntity.Name = EmployeeModel.Name; EmployeeEntity.Address = EmployeeModel.Address; EmployeeEntity.Phone = EmployeeModel.Phone; EmployeeEntity.Possition = EmployeeModel.Possition; EmployeeEntity.Private_ID = EmployeeModel.Private_ID; EmployeeEntity.Branch_ID = EmployeeModel.Branch_ID; rpEmployee.Update(EmployeeEntity); if (unitOfWorkStore.Save() >= 1) { EmployeeModel.Employee_Code = EmployeeEntity.Employee_Code; return(new Response <EmployeeModel>((int)StatusResponses.Success, MessageResConst.Success, EmployeeModel)); } else { return(new Response <EmployeeModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, EmployeeModel)); } } } catch (Exception ex) { return(new Response <EmployeeModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <Item_ColorModel> InsertItem_Color(Item_ColorModel Item_ColorModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpItem_Color = unitOfWorkStore.GetRepository <Item_Color>(); Item_Color Item_ColorEntity = new Item_Color(); Item_ColorEntity.Name = Item_ColorModel.Name; rpItem_Color.Add(Item_ColorEntity); if (unitOfWorkStore.Save() >= 1) { return(new Response <Item_ColorModel>((int)StatusResponses.Success, MessageResConst.Success, Item_ColorModel)); } else { return(new Response <Item_ColorModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, Item_ColorModel)); } } } catch (Exception ex) { return(new Response <Item_ColorModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <GroupItemModel> UpdateGroupItem(GroupItemModel GroupItemModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpGroupItem = unitOfWorkStore.GetRepository <GroupItem>(); GroupItem GroupItemEntity = rpGroupItem.GetById(GroupItemModel.GroupItem_ID); GroupItemEntity.GroupItem_ID = GroupItemModel.GroupItem_ID; GroupItemEntity.GroupItem_Code = GroupItemModel.GroupItem_Code; GroupItemEntity.Name = GroupItemModel.Name; GroupItemEntity.GroupItem_ID = GroupItemModel.GroupItem_ID; rpGroupItem.Update(GroupItemEntity); if (unitOfWorkStore.Save() >= 1) { GroupItemModel.Name = GroupItemEntity.Name; return(new Response <GroupItemModel>((int)StatusResponses.Success, MessageResConst.Success, GroupItemModel)); } else { return(new Response <GroupItemModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, GroupItemModel)); } } } catch (Exception ex) { return(new Response <GroupItemModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <GroupItemModel> InsertGroupItem(GroupItemModel GroupItemModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpGroupItem = unitOfWorkStore.GetRepository <GroupItem>(); GroupItem GroupItemEntity = new GroupItem(); GroupItemEntity.GroupItem_ID = GroupItemModel.GroupItem_ID; GroupItemEntity.GroupItem_Code = GroupItemModel.GroupItem_Code; GroupItemEntity.Name = GroupItemModel.Name; GroupItemEntity.TitleKey = FormatData.RemoveUnicode(GroupItemModel.Name); if (!string.IsNullOrEmpty(GroupItemModel.ParentId) && GroupItemModel.ParentId != "undefined") { string prid = GroupItemModel.ParentId; var listGroupItemEntity = rpGroupItem.GetAll(); var listGroupItemModel = (from obGroupItem in listGroupItemEntity select new GroupItemModel() { GroupItem_ID = obGroupItem.GroupItem_ID, GroupItem_Code = obGroupItem.GroupItem_Code, Name = obGroupItem.Name, TitleKey = obGroupItem.TitleKey, ParentId = obGroupItem.ParentId, ParenName = obGroupItem.ParenName }).ToList(); GroupItemModel tg = listGroupItemModel.Where(x => x.TitleKey == prid).FirstOrDefault(); // _category_DocumentService.FindBy<Category_DocumentFormDTO>(sp => sp.TitleKey == prid && sp.isApprove != false).FirstOrDefault(); if (tg != null) { GroupItemEntity.ParenName = tg.Name; } } rpGroupItem.Add(GroupItemEntity); if (unitOfWorkStore.Save() >= 1) { GroupItemModel.Name = GroupItemEntity.Name; return(new Response <GroupItemModel>((int)StatusResponses.Success, MessageResConst.Success, GroupItemModel)); } else { return(new Response <GroupItemModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, GroupItemModel)); } } } catch (Exception ex) { return(new Response <GroupItemModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <ItemModel> UpdateItem(ItemModel ItemModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpItem = unitOfWorkStore.GetRepository <Item>(); Item ItemEntity = rpItem.GetById(ItemModel.Item_ID); //ItemEntity.Item_ID = ItemModel.Item_ID; ItemEntity.Item_Code = ItemModel.Item_Code; ItemEntity.Name = ItemModel.Name; ItemEntity.GroupItem_ID = ItemModel.GroupItem_ID; ItemEntity.GroupItem_Sub_ID = ItemModel.GroupItem_Sub_ID; ItemEntity.AmountSale = ItemModel.AmountSale; ItemEntity.AmountOrigin = ItemModel.AmountOrigin; ItemEntity.Blance = ItemModel.Blance; ItemEntity.Item_Color_ID = ItemModel.Item_Color_ID; ItemEntity.Item_Material_ID = ItemModel.Item_Material_ID; ItemEntity.Item_Size_ID = ItemModel.Item_Size_ID; ItemEntity.Unit = ItemModel.Unit; ItemEntity.Note = ItemModel.Note; ItemEntity.AmountShip = ItemModel.AmountShip; rpItem.Update(ItemEntity); if (unitOfWorkStore.Save() >= 1) { ItemModel.Item_Code = ItemEntity.Item_Code; return(new Response <ItemModel>((int)StatusResponses.Success, MessageResConst.Success, ItemModel)); } else { return(new Response <ItemModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, ItemModel)); } } } catch (Exception ex) { return(new Response <ItemModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <CustomerModel> UpdateCustomer(CustomerModel CustomerModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpCustomer = unitOfWorkStore.GetRepository <Customer>(); Customer CustomerEntity = rpCustomer.GetById(CustomerModel.Customer_ID); CustomerEntity.Customer_ID = CustomerModel.Customer_ID; CustomerEntity.Customer_Code = CustomerModel.Customer_Code; CustomerEntity.Name = CustomerModel.Name; CustomerEntity.Phone = CustomerModel.Phone; CustomerEntity.Email = CustomerModel.Email; CustomerEntity.Address = CustomerModel.Address; CustomerEntity.Birthday = CustomerModel.Birthday; CustomerEntity.Category = CustomerModel.Category; CustomerEntity.Company_Name = CustomerModel.Company_Name; CustomerEntity.Tax_Code = CustomerModel.Tax_Code; CustomerEntity.Url = CustomerModel.Url == null? CustomerEntity.Url : CustomerModel.Url; CustomerEntity.Sex = CustomerModel.Sex; CustomerEntity.Note = CustomerModel.Note; rpCustomer.Update(CustomerEntity); if (unitOfWorkStore.Save() >= 1) { CustomerModel.Customer_Code = CustomerEntity.Customer_Code; return(new Response <CustomerModel>((int)StatusResponses.Success, MessageResConst.Success, CustomerModel)); } else { return(new Response <CustomerModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, CustomerModel)); } } } catch (Exception ex) { return(new Response <CustomerModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <BranchModel> Delete(int idBranch) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpBranch = unitOfWorkStore.GetRepository <Branch>(); Branch BranchEntity = rpBranch.GetById(idBranch); rpBranch.Delete(BranchEntity); if (unitOfWorkStore.Save() >= 1) { return(new Response <BranchModel>((int)StatusResponses.Success, MessageResConst.Success, null)); } else { return(new Response <BranchModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, null)); } } } catch (Exception ex) { return(new Response <BranchModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
// Hàm update dữ liệu public Response <VendorModel> UpdateVendor(VendorModel vendorModel) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpVendor = unitOfWorkStore.GetRepository <Vendor>(); Vendor vendorEntity = rpVendor.GetById(vendorModel.Vendor_ID); vendorEntity.Vendor_ID = vendorModel.Vendor_ID; vendorEntity.Vendor_Code = vendorModel.Vendor_Code; vendorEntity.Name = vendorModel.Name; vendorEntity.Tax_Code = vendorModel.Tax_Code; vendorEntity.Phone = vendorModel.Phone; vendorEntity.Address = vendorModel.Address; vendorEntity.Region = vendorModel.Region; vendorEntity.CommuneWard = vendorModel.CommuneWard; vendorEntity.Email = vendorModel.Email; vendorEntity.Group_Vendor = vendorModel.Group_Vendor; vendorEntity.Note = vendorModel.Note; rpVendor.Update(vendorEntity); if (unitOfWorkStore.Save() >= 1) { vendorModel.Vendor_Code = vendorEntity.Vendor_Code; return(new Response <VendorModel>((int)StatusResponses.Success, MessageResConst.Success, vendorModel)); } else { return(new Response <VendorModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, vendorModel)); } } } catch (Exception ex) { return(new Response <VendorModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <Item_MaterialModel> Delete(int idItem_Material) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpItem_Material = unitOfWorkStore.GetRepository <Item_Material>(); Item_Material Item_MaterialEntity = rpItem_Material.GetById(idItem_Material); rpItem_Material.Delete(Item_MaterialEntity); if (unitOfWorkStore.Save() >= 1) { return(new Response <Item_MaterialModel>((int)StatusResponses.Success, MessageResConst.Success, null)); } else { return(new Response <Item_MaterialModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, null)); } } } catch (Exception ex) { return(new Response <Item_MaterialModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }
public Response <GroupItemModel> Delete(int idGroupItem) { try { using (var unitOfWorkStore = new UnitOfWorkStore(dbFactory)) { var rpGroupItem = unitOfWorkStore.GetRepository <GroupItem>(); GroupItem GroupItemEntity = rpGroupItem.GetById(idGroupItem); rpGroupItem.Delete(GroupItemEntity); if (unitOfWorkStore.Save() >= 1) { return(new Response <GroupItemModel>((int)StatusResponses.Success, MessageResConst.Success, null)); } else { return(new Response <GroupItemModel>((int)StatusResponses.ErrorSystem, MessageResConst.ErrorCommonRequestParam, null)); } } } catch (Exception ex) { return(new Response <GroupItemModel>((int)StatusResponses.ErrorSystem, ex.Message, null)); } }