public Error InsertOrUpdateCustomerAdditionalInfo(CustomerAdditionalInfoModel info, UserModel user, string lockGuid) { var error = validateCustomerAdditionalInfoModel(info); if (!error.IsError) { // Check that the lock is still current if (!db.IsLockStillValid(typeof(Customer).ToString(), info.Id, lockGuid)) { error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "DeliveryInstructions"); } else { Customer temp = null; if (info.Id != 0) { temp = db.FindCustomer(info.Id); if (temp != null) { logChanges(temp, info, user); MapToEntity(info, temp); db.InsertOrUpdateCustomer(temp); info.Id = temp.Id; } } } } return(error); }
private void logChanges(Customer dbRecord, CustomerAdditionalInfoModel after, UserModel user) { CustomerAdditionalInfoModel before = new CustomerAdditionalInfoModel(); Mapper.Map(dbRecord, before); AuditService.LogChanges(typeof(Customer).ToString(), BusinessArea.CustomerAdditionalInfo, user, before, after); }
private Error validateCustomerAdditionalInfoModel(CustomerAdditionalInfoModel model) { var error = isValidNonRequiredString(getFieldValue(model.EDI_VendorNo), 30, "EDI_VendorNo", EvolutionResources.errTextDataRequiredInField); if (!error.IsError) { error = isValidRequiredInt(model.SourceId, "SourceId", EvolutionResources.errSelectionRequiredInField); } return(error); }
public CustomerAdditionalInfoModel FindCustomerAdditionalInfoModel(int customerId, CompanyModel company) { CustomerAdditionalInfoModel model = new CustomerAdditionalInfoModel { Id = customerId, CompanyId = company.Id }; var c = db.FindCustomer(customerId); if (c != null) { model = MapToAdditionalInfoModel(c); } return(model); }
public string LockCustomerAdditionalInfo(CustomerAdditionalInfoModel model) { return(db.LockRecord(typeof(Customer).ToString(), model.Id)); }
public void MapToEntity(CustomerAdditionalInfoModel model, Customer entity) { Mapper.Map <CustomerAdditionalInfoModel, Customer>(model, entity); }
public ActionResult CreateCustomer(NewCustomerViewModel model, string command) { if (ModelState.IsValid) { var customer = CustomerService.CreateCustomer(CurrentCompany, model.Customer.CountryId, model.Customer.Postcode); customer.Name = model.Customer.Name; customer.TaxId = model.Customer.TaxId; customer.CustomerTypeId = model.Customer.CustomerTypeId; // Valid date the customer model.Error = CustomerService.ValidateCustomerModel(customer); if (!model.Error.IsError) { // Now validate the address var customerAddrs = new CustomerAddressModel { CompanyId = CurrentCompany.Id, AddressTypeId = LookupService.FindLOVItemByValueModel(LOVName.AddressType, ((int)AddressType.Billing).ToString()).Id, Street = model.Customer.Street, City = model.Customer.City, State = model.Customer.Postcode, Postcode = model.Customer.Postcode, CountryId = model.Customer.CountryId }; model.Error = CustomerService.ValidateAddressModel(customerAddrs); if (!model.Error.IsError) { model.Error = CustomerService.InsertOrUpdateCustomer(customer, CurrentUser); if (!model.Error.IsError) { customerAddrs.CustomerId = customer.Id; model.Error = CustomerService.InsertOrUpdateCustomerAddress(customerAddrs); if (!model.Error.IsError) { var additionalInfo = new CustomerAdditionalInfoModel { Id = customer.Id, CompanyId = CurrentCompany.Id, RegionId = model.AdditionalInfo.RegionId }; model.Error = CustomerService.InsertOrUpdateCustomerAdditionalInfo(additionalInfo, CurrentUser, CustomerService.LockCustomer(customer)); } } } if (!model.Error.IsError) { model.Error.URL = "/Customers/Customers/Edit?Id=" + customer.Id.ToString(); } } if (model.Error.IsError) { ModelState.AddModelError("Customer_" + model.Error.FieldName, model.Error.Message); } if (!model.Error.IsError) { return(Json(model, JsonRequestBehavior.AllowGet)); } else { prepareEditModel(model); return(View("NewCustomer", model)); } } else { prepareEditModel(model); return(View("NewCustomer", model)); } }