public async Task <ActionResult> NewCustomerCarrier(CustomerCarrier custCarrier) { if (ModelState.IsValid) { var response = await _customerCarrierService.AddCarrier(custCarrier); return(Json(response)); } else { return(Json(new { success = false, responseText = "Add customer carrier failed" })); } //return PartialView("Partial_Views/NewContact", newContact); }
public async Task <int> AddCarrier(CustomerCarrier newCustomerCarrier) { _dbContext.CustomerCarriers.Add(newCustomerCarrier); try { await _dbContext.SaveChangesAsync(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { System.Diagnostics.Debug.WriteLine("{0}{1}Validation errors:{1}{2}", ex, Environment.NewLine, ex.EntityValidationErrors.Select(e => string.Join(Environment.NewLine, e.ValidationErrors.Select(v => string.Format("{0} - {1}", v.PropertyName, v.ErrorMessage))))); throw; } return(newCustomerCarrier.CarrierID); }