public void Update_NotThrowsException_StateIsValid() { var workTypeKey = new WorkTypeTableEntity { WorkTypeId = Guid.Parse("00000000-4001-0000-0000-000000000000"), }; var workTypeRepository = new WorkTypeRepository(TestEnvironment.DBSettings); var workType = workTypeRepository.Read(workTypeKey); workType.UpdateTime = DateUtil.Now; Assert.IsTrue(workTypeRepository.Update(workType)); }
public ActionResult Edit(int?id, EditWorkType editWorkType) { if (!id.HasValue) { return(RedirectToAction("Index")); } WorkTypeRepository repo = new WorkTypeRepository(context); try { WorkType workType = new WorkType(editWorkType.Id, editWorkType.Name, editWorkType.Rate); repo.Update(workType); return(RedirectToAction("Index")); } catch { } return(View(editWorkType)); }
public ActionResult Edit(int id, EditWorkType formModel) { var repo = new WorkTypeRepository(_context); try { var newWorkType = new WorkType(id, formModel.Name, formModel.Rate); repo.Update(newWorkType); return(RedirectToAction("Index")); } catch (SqlException se) { if (se.Number == 2627) { ModelState.AddModelError("Name", "That name is already taken."); } } return(View(formModel)); }
public ActionResult Edit(int id, EditWorkType workType) { WorkTypeRepository repo = new WorkTypeRepository(); try { WorkType newWorkType = new WorkType(id, workType.Name, workType.Rate); repo.Update(newWorkType); return(RedirectToAction("Index")); } catch (SqlException se) { if (se.Number == 2627) { ModelState.AddModelError("Name", "That name is already taken."); } } return(View("Edit", workType)); }
public async Task Work_Type_Repository_Should_Update_Work_Type() { // Arrange var context = TestSetUpHelper.CreateDbContext(); var repository = new WorkTypeRepository(context); var oldUnit = new WorkType() { Id = 40, Name = "TestName", EstimatedTime = 1, EstimatedCost = 100 }; var newUnit = new WorkType() { Id = 40, Name = "TestName", EstimatedTime = 1.5, EstimatedCost = 150 }; await repository.AddAsync(oldUnit); await context.SaveChangesAsync(); // Act oldUnit.Name = newUnit.Name; oldUnit.EstimatedCost = newUnit.EstimatedCost; oldUnit.EstimatedTime = newUnit.EstimatedTime; repository.Update(oldUnit); await context.SaveChangesAsync(); // Assert Assert.Equal(newUnit.Name, oldUnit.Name); Assert.Equal(newUnit.EstimatedCost, oldUnit.EstimatedCost); Assert.Equal(newUnit.EstimatedTime, oldUnit.EstimatedTime); }