Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CreateDashboardViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            DashboardDto dashboardDto = _mapper.Map <CreateDashboardViewModel, DashboardDto>(model);

            if (model.IconFile != null)
            {
                dashboardDto.IconId = await _iconManager.CreateAndGetIconId(model.IconFile);
            }

            dashboardDto.AppUserId = _userManager.GetUserId(User);

            var res = _dashboardManager.Create(dashboardDto).Result;

            if (res != null)
            {
                DashboardViewModel dashmodel = _mapper.Map <DashboardDto, DashboardViewModel>(res);
                if (!dashmodel.IsPublic)
                {
                    dashmodel.DashCreatorUserName = User.Claims.ElementAt(1).Value;
                }
                return(ViewComponent("DashboardElement", dashmodel));
            }
            else
            {
                //ModelState.AddModelError(res.Property, res.Message);
                return(View(model));
            }
        }