public static WasteContainerUpdateModel MapToWasteContainerEditModel(WasteContainerDtoModel entity) { var editModel = new WasteContainerUpdateModel(); editModel.Id = entity.Id; editModel.Name = entity.Name; editModel.Location = entity.Location; editModel.FullPecentage = entity.FullPecentage; return(editModel); }
public bool Update(WasteContainerUpdateModel wasteContainer) { WasteContainerDtoModel entity = _repository.Get(wasteContainer.Id); if (entity == null) { throw new Exception(LOCALIZATION_GENERAL_NOT_FOUND + entity.Id); } entity.Name = wasteContainer.Name; entity.FullPecentage = wasteContainer.FullPecentage; entity.Location = wasteContainer.Location; entity.Size = wasteContainer.Size; //entity.ModifiedAt = wasteContainer.ModifiedAt; //entity.ModifiedBy = wasteContainer.ModifiedBy; return(_repository.Update(entity)); }
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)); }