public StateProvince UpdateStateProvince(int stateProvinceId, StateProvince StateProvince, int userId = -1) { try { var existingStateProvince = GetStateProvince(stateProvinceId); _ctx.Entry(existingStateProvince).CurrentValues.SetValues(StateProvince); _ctx.Entry(existingStateProvince).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingStateProvince).Property(x => x.AdmCreatedBy).IsModified = false; var StateProvinceEntityEntry = _ctx.Entry(existingStateProvince); if (!Save(userId)) { return(null); } return(StateProvinceEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateStateProvince: {ex}"); return(null); } }
public UnitMeasure UpdateUnitMeasure(int unitMeasureId, UnitMeasure unitMeasure, int userId = -1) { try { var existingUnitMeasure = GetUnitMeasure(unitMeasureId); _ctx.Entry(existingUnitMeasure).CurrentValues.SetValues(unitMeasure); _ctx.Entry(existingUnitMeasure).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingUnitMeasure).Property(x => x.AdmCreatedBy).IsModified = false; var unitMeasureEntityEntry = _ctx.Entry(existingUnitMeasure); if (!Save(userId)) { return(null); } return(unitMeasureEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateUnitMeasure: {ex}"); return(null); } }
public AddressType UpdateAddressType(int addressTypeId, AddressType addressType, int userId = -1) { try { var existingAddressType = GetAddressType(addressTypeId); _ctx.Entry(existingAddressType).CurrentValues.SetValues(addressType); _ctx.Entry(existingAddressType).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingAddressType).Property(x => x.AdmCreatedBy).IsModified = false; var addressTypeEntityEntry = _ctx.Entry(existingAddressType); if (!Save(userId)) { return(null); } return(addressTypeEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateAddressType: {ex}"); return(null); } }
public ProductCategory UpdateProductCategory(int productCategoryId, ProductCategory productCategory, int userId = -1) { try { var existingProductCategory = GetProductCategory(productCategoryId); _ctx.Entry(existingProductCategory).CurrentValues.SetValues(productCategory); _ctx.Entry(existingProductCategory).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingProductCategory).Property(x => x.AdmCreatedBy).IsModified = false; var productCategoryEntityEntry = _ctx.Entry(existingProductCategory); if (!Save(userId)) { return(null); } return(productCategoryEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateProductCategory: {ex}"); return(null); } }
public ProductMaterial UpdateProductMaterial(int addressMaterialId, ProductMaterial addressMaterial, int userId = -1) { try { var existingProductMaterial = GetProductMaterial(addressMaterialId); _ctx.Entry(existingProductMaterial).CurrentValues.SetValues(addressMaterial); _ctx.Entry(existingProductMaterial).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingProductMaterial).Property(x => x.AdmCreatedBy).IsModified = false; var addressMaterialEntityEntry = _ctx.Entry(existingProductMaterial); if (!Save(userId)) { return(null); } return(addressMaterialEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateProductMaterial: {ex}"); return(null); } }
public SalesOrderDetail UpdateSalesOrderDetail(int salesOrderDetailId, SalesOrderDetail salesOrderDetail, int userId = -1) { try { var existingSalesOrderDetail = GetSalesOrderDetail(salesOrderDetailId); _ctx.Entry(existingSalesOrderDetail).CurrentValues.SetValues(salesOrderDetail); _ctx.Entry(existingSalesOrderDetail).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingSalesOrderDetail).Property(x => x.AdmCreatedBy).IsModified = false; var salesOrderDetailEntityEntry = _ctx.Entry(existingSalesOrderDetail); if (!Save(userId)) { return(null); } return(salesOrderDetailEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateSalesOrderDetail: {ex}"); return(null); } }
public CountryRegion UpdateCountryRegion(int countryRegionId, CountryRegion countryRegion, int userId = -1) { try { var existingCountryRegion = GetCountryRegion(countryRegionId); _ctx.Entry(existingCountryRegion).CurrentValues.SetValues(countryRegion); _ctx.Entry(existingCountryRegion).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingCountryRegion).Property(x => x.AdmCreatedBy).IsModified = false; var CountryRegionEntityEntry = _ctx.Entry(existingCountryRegion); if (!Save(userId)) { return(null); } return(CountryRegionEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateCountryRegion: {ex}"); return(null); } }
public BillOfMaterial UpdateBillOfMaterial(int billOfMaterialsId, BillOfMaterial billOfMaterial, int userId = -1) { try { var existingBillOfMaterial = GetBillOfMaterial(billOfMaterialsId); _ctx.Entry(existingBillOfMaterial).CurrentValues.SetValues(billOfMaterial); _ctx.Entry(existingBillOfMaterial).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingBillOfMaterial).Property(x => x.AdmCreatedBy).IsModified = false; var billOfMaterialEntityEntry = _ctx.Entry(existingBillOfMaterial); if (!Save(userId)) { return(null); } return(billOfMaterialEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateBillOfMaterial: {ex}"); return(null); } }
public void MarkAsRead(int userId, int notificationId) { Notification?existing = context.Notifications.Find(notificationId); if (existing == null) { throw new Exception(); } EntityEntry <Notification> entry = context.Entry(existing); entry.CurrentValues["Read"] = true; context.SaveChanges(); }
public Post Update(Post post) { Post?existing = context.Posts.Find(post.Id); if (existing == null) { throw new Exception(); } EntityEntry <Post> entry = context.Entry(existing); entry.CurrentValues.SetValues(post); context.SaveChanges(); return(entry.Entity); }
public Tag Update(Tag tag) { Tag?existing = context.Tags.Find(tag.Id); if (existing == null) { throw new Exception(); } EntityEntry <Tag> entry = context.Entry(existing); entry.CurrentValues.SetValues(tag); entry.CurrentValues["CreatedDate"] = existing.CreatedDate; context.SaveChanges(); return(entry.Entity); }
public Category Update(Category category) { Category?existing = context.Categories.Find(category.Id); if (existing == null) { throw new Exception(); } EntityEntry <Category> entry = context.Entry(existing); entry.CurrentValues.SetValues(category); entry.CurrentValues["CreatedDate"] = existing.CreatedDate; context.SaveChanges(); return(entry.Entity); }
public Vendor UpdateVendor(int businessEntityId, Vendor vendor, int userId = -1) { try { var existingVendor = GetVendor(businessEntityId); _ctx.Entry(existingVendor).CurrentValues.SetValues(vendor); _ctx.Entry(existingVendor).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingVendor).Property(x => x.AdmCreatedBy).IsModified = false; var vendorEntityEntry = _ctx.Entry(existingVendor); // Delete children foreach (var businessEntityAddress in existingVendor.BusinessEntity.BusinessEntityAddresses) { if (!vendor.BusinessEntity.BusinessEntityAddresses.Any(c => c.BusinessEntityAddressId == businessEntityAddress.BusinessEntityAddressId)) { _ctx.BusinessEntityAddresses.Remove(businessEntityAddress); _ctx.Addresses.Remove(businessEntityAddress.Address); } } foreach (var businessEntityAddress in vendor.BusinessEntity.BusinessEntityAddresses) { var existingBusinessEntityAddress = GetBusinessEntityAddress(businessEntityAddress.BusinessEntityAddressId); if (existingBusinessEntityAddress == null) { businessEntityAddress.BusinessEntityId = businessEntityId; _ctx.BusinessEntityAddresses.Add(businessEntityAddress); _ctx.Addresses.Add(businessEntityAddress.Address); } else { _ctx.Entry(existingBusinessEntityAddress).CurrentValues.SetValues(businessEntityAddress); _ctx.Entry(existingBusinessEntityAddress).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingBusinessEntityAddress).Property(x => x.AdmCreatedBy).IsModified = false; _ctx.Entry(existingBusinessEntityAddress.Address).CurrentValues.SetValues(businessEntityAddress.Address); _ctx.Entry(existingBusinessEntityAddress.Address).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingBusinessEntityAddress.Address).Property(x => x.AdmCreatedBy).IsModified = false; } } // Delete children foreach (var businessEntityContact in existingVendor.BusinessEntity.BusinessEntityContacts) { if (!vendor.BusinessEntity.BusinessEntityContacts.Any(c => c.BusinessEntityContactId == businessEntityContact.BusinessEntityContactId)) { _ctx.BusinessEntityContacts.Remove(businessEntityContact); _ctx.Persons.Remove(businessEntityContact.Person); } } foreach (var businessEntityContact in vendor.BusinessEntity.BusinessEntityContacts) { var existingBusinessEntityContact = GetBusinessEntityContact(businessEntityContact.BusinessEntityContactId); if (existingBusinessEntityContact == null) { businessEntityContact.BusinessEntityId = businessEntityId; _ctx.BusinessEntityContacts.Add(businessEntityContact); _ctx.Persons.Add(businessEntityContact.Person); } else { _ctx.Entry(existingBusinessEntityContact).CurrentValues.SetValues(businessEntityContact); _ctx.Entry(existingBusinessEntityContact).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingBusinessEntityContact).Property(x => x.AdmCreatedBy).IsModified = false; _ctx.Entry(existingBusinessEntityContact.Person).CurrentValues.SetValues(businessEntityContact.Person); _ctx.Entry(existingBusinessEntityContact.Person).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingBusinessEntityContact.Person).Property(x => x.AdmCreatedBy).IsModified = false; } } // Delete children foreach (var businessEntityEmail in existingVendor.BusinessEntity.BusinessEntityEmails) { if (!vendor.BusinessEntity.BusinessEntityEmails.Any(c => c.BusinessEntityEmailId == businessEntityEmail.BusinessEntityEmailId)) { _ctx.BusinessEntityEmails.Remove(businessEntityEmail); } } foreach (var businessEntityEmail in vendor.BusinessEntity.BusinessEntityEmails) { var existingBusinessEntityEmail = GetBusinessEntityEmail(businessEntityEmail.BusinessEntityEmailId); if (existingBusinessEntityEmail == null) { businessEntityEmail.BusinessEntityId = businessEntityId; _ctx.BusinessEntityEmails.Add(businessEntityEmail); } else { _ctx.Entry(existingBusinessEntityEmail).CurrentValues.SetValues(businessEntityEmail); _ctx.Entry(existingBusinessEntityEmail).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingBusinessEntityEmail).Property(x => x.AdmCreatedBy).IsModified = false; } } // Delete children foreach (var businessEntityPhone in existingVendor.BusinessEntity.BusinessEntityPhones) { if (!vendor.BusinessEntity.BusinessEntityPhones.Any(c => c.BusinessEntityPhoneId == businessEntityPhone.BusinessEntityPhoneId)) { _ctx.BusinessEntityPhones.Remove(businessEntityPhone); } } foreach (var businessEntityPhone in vendor.BusinessEntity.BusinessEntityPhones) { var existingBusinessEntityPhone = GetBusinessEntityPhone(businessEntityPhone.BusinessEntityPhoneId); if (existingBusinessEntityPhone == null) { businessEntityPhone.BusinessEntityId = businessEntityId; _ctx.BusinessEntityPhones.Add(businessEntityPhone); } else { _ctx.Entry(existingBusinessEntityPhone).CurrentValues.SetValues(businessEntityPhone); _ctx.Entry(existingBusinessEntityPhone).Property(x => x.AdmCreated).IsModified = false; _ctx.Entry(existingBusinessEntityPhone).Property(x => x.AdmCreatedBy).IsModified = false; } } if (!Save(userId)) { return(null); } return(vendorEntityEntry.Entity); } catch (Exception ex) { _logger.LogError($"Failed in UpdateVendor: {ex}"); return(null); } }