public async Task<IServiceResult> CreateProjectVersion(ProjectVersionEditViewModel model)
        {
            var result = new ServiceResult<ProjectVersionEditViewModel>();

            try
            {
                var project = await ProjectStore.GetAll().Include(p => p.Versions).SingleOrDefaultAsync(p => p.Id == model.ProjectId);
                if (project == null)
                {
                    result.AddError(m => m.ProjectId, "Ilyen azonosítóval nem létezik projekt!");
                    return result;
                }
                
                var version = Mapper.Map<ProjectVersionEditViewModel, ProjectVersion>(model);
                version.Project = project;

                await ProjectVersionStore.InsertAsync(version);
            }
            catch (Exception e)
            {
                Log.Error(e.Message, e);

                result.AddError("", e.Message);
            }

            return result;
        }
        public async Task<IServiceResult> UpdateProjectVersion(ProjectVersionEditViewModel model)
        {
            var result = new ServiceResult<ProjectVersionEditViewModel>();

            try
            {
                await ProjectVersionStore.UpdateAsync(Mapper.Map<ProjectVersionEditViewModel, ProjectVersion>(model));
            }
            catch (Exception e)
            {
                Log.Error(e.Message, e);

                result.AddError("", e.Message);
            }

            return result;
        }
Exemplo n.º 3
0
        public async Task<ActionResult> EditVersion(ProjectVersionEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await ProjectVersionService.UpdateProjectVersion(model);
                if (result.Succeeded)
                {
                    return RedirectToAction("DetailsVersions", new { id = model.ProjectId });
                }
                else
                {
                    AddModelErrors(result.Errors);
                    return View("EditVersion", model);
                }
            }

            return View("EditVersion", model);
        }