public async Task <IActionResult> ComponentTypeDetail(int?componentTypeDetailId, int componentTypeId) { var detail = await _componentTypeDetailService.GetByIdAsync(componentTypeDetailId); if (detail == null) { var model = new ComponentTypeDetailInputModel { ComponentTypeId = componentTypeId }; return(View(model)); } else { var model = _mapper.Map <ComponentTypeDetailInputModel>(detail); return(View(model)); } }
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}")); }