public void UpdateTest() { var entity = _memoryDbContext.Containers.FirstOrDefault(); var entityEditModel = Builder <WasteContainerUpdateModel> .CreateNew() .With(c => c.Id = entity.Id).Build(); Assert.IsTrue(_wasteContainerService.Update(entityEditModel)); }
public IActionResult Edit([FromForm] WasteContainerUpdateModel entity) { if (ModelState.IsValid) { //TODO: string currentUser = HttpContext?.User?.Identity?.Name; string currentUser = "******"; if (!String.IsNullOrEmpty(currentUser)) { //AuditedEntityMapper<WasteContainerEditModel>.FillModifyAuditedEntityFields(entity, currentUser); try { _wasteContainerService.Update(entity); } catch (DbUpdateConcurrencyException) { if (!WasteContainerExists(entity.Id)) { _logger.LogError(LOCALIZATION_ERROR_NOT_FOUND); return(NotFound().WithError(LOCALIZATION_ERROR_NOT_FOUND)); } else { _logger.LogError(LOCALIZATION_ERROR_CONCURENT_EDIT); return(NotFound().WithError(LOCALIZATION_ERROR_CONCURENT_EDIT)); } } return(RedirectToAction(nameof(Details), new { id = entity.Id }).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE)); }