public ActionResult Update([FromBody] CompanyViewModel company) { var currentRes = _bo.Read(company.Id); if (!currentRes.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } var current = currentRes.Result; if (current == null) { return(NotFound()); } if (current.Name == company.Name) { return(StatusCode((int)HttpStatusCode.NotModified)); } if (current.Name != company.Name) { current.Name = company.Name; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok()); }
public void TestUpdatetCompany() { BoraNowSeeder.Seed(); var cbo = new CompanyBusinessObject(); var resList = cbo.List(); var item = resList.Result.FirstOrDefault(); var pbo = new ProfileBusinessObject(); var profile = new Profile("II", "AA"); pbo.Create(profile); var company = new Company("B", "C", "1263", "2434", profile.Id); item.Name = company.Name; item.Representative = company.Representative; item.PhoneNumber = company.PhoneNumber; item.VatNumber = company.VatNumber; item.ProfileId = company.ProfileId; var resUpdate = cbo.Update(item); resList = cbo.List(); Assert.IsTrue(resUpdate.Success && resList.Success && resList.Result.First().Name == company.Name && resList.Result.First().Representative == company.Representative && resList.Result.First().PhoneNumber == company.PhoneNumber && resList.Result.First().VatNumber == company.VatNumber && resList.Result.First().ProfileId == company.ProfileId); }
public void TestUpdateSameVATNumberCompany() { ContextSeeder.Seed(); var bo = new CompanyBusinessObject(); var com = new Company("Sonae", 12345); bo.Create(com); com.VatNumber = 123456789; var resUpdate = bo.Update(com); Assert.IsTrue(resUpdate.Success && resUpdate.Message == "Vat number already exists"); }
public void TestUpdateSameNameCompany() { ContextSeeder.Seed(); var bo = new CompanyBusinessObject(); var com = new Company("Sonae", 12345); bo.Create(com); com.Name = "pingo ácido"; var resUpdate = bo.Update(com); Assert.IsTrue(resUpdate.Success && resUpdate.Message == "Name already exists"); }
public void TestUpdateCompany() { ContextSeeder.Seed(); var bo = new CompanyBusinessObject(); var resList = bo.List(); var item = resList.Result.FirstOrDefault(); item.Name = "Jerónimo Martins"; var resUpdate = bo.Update(item); var resNotList = bo.ListNotDeleted().Result; Assert.IsTrue(resUpdate.Success && resNotList.First().Name == "Jerónimo Martins"); }
public ActionResult Update([FromBody] CompanyViewModel vm) { var currentResult = _bo.Read(vm.Id); if (!currentResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Name == vm.Name && current.Representative == vm.Representative && current.ProfileId == vm.ProfileId && current.PhoneNumber == vm.PhoneNumber && current.VatNumber == vm.VatNumber) { return(new ObjectResult(HttpStatusCode.NotModified)); } if (current.Name != vm.Name) { current.Name = vm.Name; } if (current.Representative != vm.Representative) { current.Representative = vm.Representative; } if (current.PhoneNumber != vm.PhoneNumber) { current.PhoneNumber = vm.PhoneNumber; } if (current.VatNumber != vm.VatNumber) { current.VatNumber = vm.VatNumber; } if (current.ProfileId != vm.ProfileId) { current.ProfileId = vm.ProfileId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } return(Ok()); }
public ActionResult Update([FromBody] CompanyViewModel comp) { var currentResult = _bo.Read(comp.Id); if (!currentResult.Success) { return(InternalServerError()); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Name == comp.Name && current.VatNumber == comp.VatNumber) { return(NotModified()); } if (current.Name != comp.Name) { current.Name = comp.Name; } if (current.VatNumber != comp.VatNumber) { current.VatNumber = comp.VatNumber; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(InternalServerError()); } return(Ok()); }