public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Title,Text,CreatedAt,State,PresentationId,ReplyToCommentId")] CommentModel commentModel) { if (id != commentModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(commentModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentModelExists(commentModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ReplyToCommentId"] = new SelectList(_context.CommentModel, "Id", "Name", commentModel.ReplyToCommentId); ViewData["PresentationId"] = new SelectList(_context.PresentaionModel, "Id", "Name", commentModel.PresentationId); return(View(commentModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,ProjectId")] IssueModel issueModel) { if (id != issueModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(issueModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IssueModelExists(issueModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", issueModel.ProjectId); return(View(issueModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Image,Description")] TechModel techModel, IFormFile imageFile) { if (id != techModel.Id) { return(NotFound()); } if (ModelState.IsValid) { if (imageFile != null) { var UploadImage = new UploadImage(_env, _config); if (techModel.Image == null) { techModel.Image = await UploadImage.Create(imageFile); } else { techModel.Image = await UploadImage.Edit(techModel.Image, imageFile); } } try { _context.Update(techModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TechModelExists(techModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(techModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Image,DescriptionShort,DescriptionLong,EstimateTime,EstimatePrice,LastChange,ProjectId")] PresentaionModel presentaionModel, IFormFile imageFile) { if (id != presentaionModel.Id) { return(NotFound()); } if (ModelState.IsValid) { string fileName = null; string fullFilePath = null; string uploadDirectory = _uploadDirectory; System.IO.Directory.CreateDirectory(uploadDirectory); if (imageFile != null && imageFile.Length > 0) { string fileExt = Path.GetExtension(imageFile.FileName); if (string.IsNullOrEmpty(fileExt) || !_permittedExtensions.Contains(fileExt)) { Message = "Error : Invalid File Extension"; ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", presentaionModel.ProjectId); return(View()); } if (imageFile.Length > _fileSizeLimit) { Message = "Error : File max size must be 10MB"; ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", presentaionModel.ProjectId); return(View()); } if (presentaionModel.Image == null) { do { fileName = Guid.NewGuid().ToString() + fileExt; fullFilePath = string.Format(@"{0}\{1}", uploadDirectory, fileName); } while (System.IO.File.Exists(fullFilePath)); presentaionModel.Image = string.Format(@"{0}\{1}", @"images\upload", fileName); } else { fullFilePath = string.Format(@"{0}\{1}", _env.WebRootPath, presentaionModel.Image); } using (var stream = System.IO.File.Create(fullFilePath)) { await imageFile.CopyToAsync(stream); } } try { presentaionModel.LastChange = DateTime.Now; _context.Update(presentaionModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PresentaionModelExists(presentaionModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", presentaionModel.ProjectId); return(View(presentaionModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,DescriptionShort,DescriptionLong,Image")] ProjectModel projectModel, IFormFile imageFile, [Bind("techIds")] int[] techIds) { if (id != projectModel.Id) { return(NotFound()); } projectModel = await _context.ProjectModel.Include(t => t.Teches).FirstOrDefaultAsync(p => p.Id == id); if (ModelState.IsValid) { if (imageFile != null) { var UploadImage = new UploadImage(_env, _config); if (projectModel.Image == null) { projectModel.Image = await UploadImage.Create(imageFile); } else { projectModel.Image = await UploadImage.Edit(projectModel.Image, imageFile); } } try { foreach (var tech in projectModel.Teches.ToList()) { if (!techIds.Contains(tech.Id)) { projectModel.Teches.Remove(tech); } } foreach (int techId in techIds) { if (!projectModel.Teches.Any(t => t.Id == techId)) { var tech = _context.TechModel.First(t => t.Id == techId); projectModel.Teches.Add(tech); } } _context.Update(projectModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectModelExists(projectModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(projectModel)); }