public async Task Update(OrganizationInputeModel model) { var usersession = GetUserSession(); var organization = await DbContext.Organizations.FirstOrDefaultAsync(x => x.ID == model.ID); Mapper.Map <OrganizationInputeModel, Organization>(model, organization); organization.CreateBy = organization.UpdateBy = usersession.UserFullName; organization.UpdateDate = organization.CreateDate = DateTimeService.ProvideDateTime(); DbContext.Attach(organization).State = EntityState.Modified; var customers = await DbContext.Customers.Where(x => x.CustomerOrganizationID == organization.ID).ToListAsync(); var suppliers = await DbContext.Suppliers.Where(x => x.SupplierOrganizationID == organization.ID).ToListAsync(); foreach (var item in customers) { Mapper.Map <OrganizationInputeModel, Models.Customer>(model, item); DbContext.Attach(item).State = EntityState.Modified; } foreach (var item in suppliers) { Mapper.Map <OrganizationInputeModel, Models.Supplier>(model, item); DbContext.Attach(item).State = EntityState.Modified; } await DbContext.SaveChangesAsync(); }
public async Task DeleteRecord(Guid id) { using (var transaction = DbContext.Database.BeginTransaction()) { var userSession = GetUserSession(); var customer = await DbContext.Customers.FirstOrDefaultAsync(m => m.ID == id); var organization = await DbContext.Organizations.FirstOrDefaultAsync(m => m.ID == customer.CustomerOrganizationID); customer.Deleted = 1; organization.Deleted = 1; organization.UpdateBy = customer.UpdateBy = userSession.UserFullName; organization.UpdateDate = customer.UpdateDate = DateTimeService.ProvideDateTime(); DbContext.Attach(customer).State = EntityState.Modified; DbContext.Attach(organization).State = EntityState.Modified; await DbContext.SaveChangesAsync(); var list = DbContext.Users.Where(x => x.OrganizationID == organization.ID); foreach (var item in list) { await _userManager.DeleteAsync(item); } transaction.Commit(); } }
private void SetBaseFields(User instance) { var userSession = GetUserSession(); instance.OrganizationID = userSession.OrganizationID; instance.CreateDate = DateTimeService.ProvideDateTime(); instance.UpdateDate = DateTimeService.ProvideDateTime(); instance.CreateBy = userSession.UserFullName; instance.UpdateBy = userSession.UserFullName; }
private async Task CreateSupplier(SupplierInputModel model, Guid supplierOrganizationID) { var userSession = GetUserSession(); var supplier = Mapper.Map <ERP.Models.Supplier>(model); supplier.SupplierOrganizationID = supplierOrganizationID; supplier.OrganizationID = userSession.OrganizationID; supplier.CreateBy = supplier.UpdateBy = userSession.UserFullName; supplier.UserID = userSession.UserID; supplier.CreateDate = supplier.UpdateDate = DateTimeService.ProvideDateTime(); await DbContext.Suppliers.AddAsync(supplier); await DbContext.SaveChangesAsync(); }
private async Task CreateCustomer(CustomerInputeModel model, Guid customerOrganizationID) { var usersession = GetUserSession(); var customer = Mapper.Map <ERP.Models.Customer>(model); customer.CustomerOrganizationID = customerOrganizationID; customer.OrganizationID = usersession.OrganizationID; customer.CreateBy = customer.UpdateBy = usersession.UserFullName; customer.UserID = usersession.UserID; customer.CreateDate = customer.UpdateDate = DateTimeService.ProvideDateTime(); await DbContext.Customers.AddAsync(customer); await DbContext.SaveChangesAsync(); }
public async Task UpdateRecord(CustomerInputeModel inputModel) { var userSession = GetUserSession(); var customer = await DbContext.Customers.FirstOrDefaultAsync(m => m.ID == inputModel.ID); var organization = await DbContext.Organizations.FirstOrDefaultAsync(m => m.ID == customer.CustomerOrganizationID); Mapper.Map <CustomerInputeModel, ERP.Models.Customer>(inputModel, customer); Mapper.Map <CustomerInputeModel, Organization>(inputModel, organization); organization.UpdateBy = customer.UpdateBy = userSession.UserFullName; organization.UpdateDate = customer.UpdateDate = DateTimeService.ProvideDateTime(); DbContext.Attach(customer).State = EntityState.Modified; DbContext.Attach(organization).State = EntityState.Modified; await DbContext.SaveChangesAsync(); }
private async Task <Guid> CreateCustomerOrganization(CustomerInputeModel model) { var userSession = GetUserSession(); Guid id = Guid.NewGuid(); var instance = this.Mapper.Map <Organization>(model); instance.ProviderOrganizationID = userSession.OrganizationID; instance.ID = id; instance.CreateBy = userSession.UserFullName; instance.UpdateBy = userSession.UserFullName; instance.CreateDate = DateTimeService.ProvideDateTime(); instance.UpdateDate = DateTimeService.ProvideDateTime(); await DbContext.Organizations.AddAsync(instance); await DbContext.SaveChangesAsync(); return(id); }