コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Description,Title,TimeZone,Culture,Norm")] EditViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Map EditViewModel to Project
                    Mapper.Initialize(cfg => cfg.CreateMap <EditViewModel, Project>());
                    var project = Mapper.Map <Project>(viewModel);

                    if (!await CanAccessToProject(project))
                    {
                        return(NotFound());
                    }

                    await _projects.UpdateAsync(project);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await _projects.ExistsAsync(viewModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("List"));
            }
            return(View(viewModel));
        }