Exemplo n.º 1
0
        public async Task <IActionResult> Edit(EditProjectInputModel editModel)
        {
            bool isValid;

            // If projectId does not exist or user has no ref to the project.
            if (!IsCurrentUserInProject(editModel.ProjectId))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                isValid = false;
                var responseHtml = await this.RenderViewAsStringAsync("Edit", editModel, true);

                return(Json(new { isValid = isValid, html = responseHtml }));
            }

            try
            {
                await this.projectsService.UpdateAsync(editModel);

                isValid = true;

                return(Json(new { isValid = isValid, newDescription = editModel.Description }));
            }
            catch (Exception)
            {
                this.ModelState.AddModelError(string.Empty, ErrorConstants.ContactSupportMessage);
                isValid = false;

                return(Json(new { isValid = isValid, newDescription = editModel.Description }));
            }
        }
Exemplo n.º 2
0
        public async Task UpdateAsync(EditProjectInputModel editModel)
        {
            var project = await this.projectRepo.All()
                          .Where(x => x.Id == editModel.ProjectId)
                          .FirstOrDefaultAsync();

            project.Description = editModel.Description;
            project.ModifiedOn  = DateTime.UtcNow;

            this.projectRepo.Update(project);

            await this.projectRepo.SaveChangesAsync();
        }