public bool Add(WasteContainerCreateModel entity) { WasteContainerDtoModel wasteContainer = new WasteContainerDtoModel { Name = entity.Name, FullPecentage = entity.FullPecentage, Location = entity.Location, Size = entity.Size }; return(_repository.Add(wasteContainer)); }
public IActionResult Create([FromForm] WasteContainerCreateModel entity) { if (ModelState.IsValid) { //TODO: string currentUser = HttpContext?.User?.Identity?.Name; string currentUser = "******"; if (!String.IsNullOrEmpty(currentUser)) { try { //AuditedEntityMapper<WasteContainerCreateModel>.FillCreateAuditedEntityFields(entity, currentUser); bool statusResult = _wasteContainerService.Add(entity); if (statusResult) { return(RedirectToAction(nameof(Index)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { return(RedirectToAction(nameof(Index)).WithError(LOCALIZATION_ERROR_DEFAULT)); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(RedirectToAction(nameof(Index)).WithError(ex.Message)); } } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE)); }