Beispiel #1
0
        public async Task <IActionResult> ComponentTypeDetail(ComponentTypeDetailInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var detail = await _componentTypeDetailService.GetByIdAsync(model.Id);

            if (detail == null)
            {
                detail = new ComponentTypeDetail
                {
                    Name            = model.Name,
                    Unit            = model.Unit,
                    Symbol          = model.Symbol,
                    IsPrimary       = model.IsPrimary,
                    ComponentTypeId = model.ComponentTypeId,
                    CreatedDateTime = DateTime.UtcNow,
                    CreatedByUserId = _userManager.GetUserId(User),
                    IsActive        = true
                };
            }
            else
            {
                detail.Name   = model.Name;
                detail.Unit   = model.Unit;
                detail.Symbol = model.Symbol;

                detail.LastUpdatedDateTime = DateTime.UtcNow;
                detail.LastUpdatedByUserId = _userManager.GetUserId(User);
            }

            if (model.IsPrimary)
            {
                detail.IsPrimary = model.IsPrimary;
                await _componentTypeDetailService.ResetPrimaryStatuses(detail);
            }

            await _componentTypeDetailService.SaveChangesAsync(detail);

            return(Redirect($"/Admin/ComponentType?componentTypeId={model.ComponentTypeId}"));
        }
Beispiel #2
0
        public async Task ResetPrimaryStatuses_WhenArgumentIsNull_ShouldReturnFalse()
        {
            var result = await _componentTypeDetailService.ResetPrimaryStatuses(null);

            Assert.IsFalse(result);
        }