public JsonResult UpdateCompany(COMPANIES company) { var result = new JsonResult(); var validationFailures = new List <ValidationFailures>(); validationFailures = validateSave(company).ToList(); if (validationFailures.Any()) { result = Json(new { failures = validationFailures[0].Message }); return(result); } else { var newCompany = db.COMPANIES.SingleOrDefault(b => b.CompanyId == company.CompanyId); if (newCompany != null) { newCompany.Name = company.Name; newCompany.Cnpj = company.Cnpj; newCompany.CompanyId = company.CompanyId; newCompany.Email = company.Email; newCompany.Phone = company.Phone; db.SaveChanges(); return(Json(new { success = true })); } } return(Json(new { Success = false })); }
public JsonResult SaveCompany(COMPANIES company) { var result = new JsonResult(); var validationFailures = new List <ValidationFailures>(); validationFailures = validateSave(company).ToList(); if (validationFailures.Any()) { result = Json(new { failures = validationFailures[0].Message }); return(result); } else { company.CreatedWhen = DateTime.Now.Date; db.COMPANIES.Add(company); db.SaveChanges(); result = Json(new { success = true }); } return(result); }
public static IList <ValidationFailures> validateSave(COMPANIES company) { var failures = new List <ValidationFailures>(); if (company == null) { failures.Add(new ValidationFailures { Message = "Por favor Preencha todos os Campos." }); } else { if (string.IsNullOrEmpty(company.Name)) { failures.Add(new ValidationFailures { Message = "Por favor informe o nome da empresa." }); } if (string.IsNullOrEmpty(company.Cnpj)) { failures.Add(new ValidationFailures { Message = "Por favor informe o Cnpj da empresa." }); } var isValid = IsCnpj(company.Cnpj); if (!isValid) { failures.Add(new ValidationFailures { Message = "Por favor informe um Cnpj Válido." }); } } return(failures); }
public static string CompanyName() { return(COMPANIES.RandomElement()); }