public void AddTest()
        {
            var count = _memoryDbContext.Containers.Count();
            var wasteManagementCreateModel = Builder <WasteContainerCreateModel> .CreateNew().Build();

            Assert.IsTrue(_wasteContainerService.Add(wasteManagementCreateModel));
            Assert.IsTrue(_memoryDbContext.Containers.Count() == count + 1);
        }
Exemplo n.º 2
0
        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));
        }