public async Task <IActionResult> EditProjectConfirm(ProjectClientViewModel model) { string nvm; try { if (!ModelState.IsValid) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Wrong_Values, contentRootPath); return(RedirectToAction("ProjectList", new { notification = nvm })); } if (model != null) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); var doesExist = _dbProject.GetAll().Where(x => (x.Title == model.Title || x.LatinTitle.ToLower() == model.LatinTitle.ToLower()) && x.Id != model.Id).ToList(); if (doesExist.Count > 0) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.DuplicatedValue, contentRootPath); return(RedirectToAction("ProjectList", new { notification = nvm })); } var modifyingRecord = _dbProject.FindById(model.Id); if (modifyingRecord != null) { modifyingRecord.Title = model.Title; modifyingRecord.LatinTitle = model.LatinTitle; modifyingRecord.ProjectManagerFullName = model.ProjectManagerFullName; modifyingRecord.CategoryId = model.CategoryId; modifyingRecord.Price = model.Price > 0 ? model.Price : 0; modifyingRecord.Collaborators = model.Collaborators != null ? model.Collaborators : modifyingRecord.Collaborators; modifyingRecord.ClientId = model.ClientId; modifyingRecord.Technologies = model.Technologies; modifyingRecord.Starts = model.Starts != null?CustomizeCalendar.PersianToGregorian(model.Starts ?? DateTime.Now) : DateTime.Now; modifyingRecord.Ends = model.Ends != null?CustomizeCalendar.PersianToGregorian(model.Ends ?? DateTime.Now) : DateTime.Now.AddMonths(2); modifyingRecord.Description = model.Description; modifyingRecord.Status = model.Status; modifyingRecord.ModifiedByUsers = modifyingRecord.ModifiedByUsers + $" - ویرایش شده توسط: {currentUser.UserName} ، در مورخه: {CustomizeCalendar.GregorianToPersianDateTime(DateTime.Now)} \n "; _dbProject.Update(modifyingRecord); nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Update, contentRootPath); return(RedirectToAction("ProjectList", new { notification = nvm })); } } nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Update, contentRootPath); return(RedirectToAction("ProjectList", new { notification = nvm })); } catch (Exception ex) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Operation, contentRootPath); return(RedirectToAction("ProjectList", new { notification = nvm })); } }
public async Task <IActionResult> Create() { ProjectClientViewModel model = new ProjectClientViewModel() { ClientList = await _context.Client.ToListAsync(), Project = new Models.Project() }; return(View(model)); }
}//end AddProject public async Task <IActionResult> AddProjectConfirm(ProjectClientViewModel model) { string nvm; try { if (!ModelState.IsValid) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Wrong_Values, contentRootPath); return(RedirectToAction("Add", new { notification = nvm })); } if (model != null) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (currentUser != null) { Projects newProject = new Projects() { Title = model.Title, LatinTitle = model.LatinTitle, Status = model.Status, CategoryId = model.CategoryId > 0 ? model.CategoryId : null, ClientId = model.ClientId > 0 ? model.ClientId : null, Collaborators = model.Collaborators, ProjectManagerFullName = model.ProjectManagerFullName, Description = model.Description, DefinedByUser = currentUser, Starts = model.Starts != null?CustomizeCalendar.PersianToGregorian(model.Starts ?? DateTime.Now) : DateTime.Now, Ends = model.Ends != null?CustomizeCalendar.PersianToGregorian(model.Ends ?? DateTime.Now) : DateTime.Now.AddMonths(2), Technologies = model.Technologies, Price = model.Price > 0 ? model.Price : 0 }; _dbProject.Insert(newProject); nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Insert, contentRootPath); return(RedirectToAction("AddProject", new { notification = nvm })); } } nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Insert, contentRootPath); return(RedirectToAction("AddProject", new { notification = nvm })); } catch (Exception ex) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Operation, contentRootPath); return(RedirectToAction("AddProject", new { notification = nvm })); } }//end AddProjectConfirm
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var project = await _context.Project.SingleOrDefaultAsync(m => m.ProjectID == id); if (project == null) { return(NotFound()); } ProjectClientViewModel model = new ProjectClientViewModel() { ClientList = await _context.Client.ToListAsync(), Project = project }; return(View(model)); }
public async Task <IActionResult> Create(Project project) { if (ModelState.IsValid) { DateTime dDate = new DateTime(0001, 01, 01); DateTime nDate = DateTime.Today; if (project.RenewalDate == dDate) { if (project.StartDate == dDate) { if (project.EndDate == dDate) { project.EndDate = nDate.AddMonths(2); project.StartDate = nDate; project.RenewalDate = nDate; _context.Add(project); await _context.SaveChangesAsync(); string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; var projectFromDb = await _context.Project.FindAsync(project.ProjectID); string extension; if (files.Count > 0) { extension = Path.GetExtension(files[0].FileName); string imageName = project.ProjectID + extension; string path = Path.Combine(webRootPath + SD.DefaultImagePath, imageName); using (var fileStream = new FileStream(path, FileMode.Create)) { files[0].CopyTo(fileStream); } } else { extension = SD.DefaultImageExtension; var uploads = Path.Combine(webRootPath + SD.DefaultImagePath + SD.DefaultProjectImage); System.IO.File.Copy(uploads, webRootPath + SD.DefaultImagePath + project.ProjectID.ToString() + extension); } projectFromDb.ProjectImage = SD.DefaultImagePath + project.ProjectID + extension; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { project.StartDate = nDate; _context.Add(project); await _context.SaveChangesAsync(); string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; var projectFromDb = await _context.Project.FindAsync(project.ProjectID); string extension; if (files.Count > 0) { extension = Path.GetExtension(files[0].FileName); string imageName = project.ProjectID + extension; string path = Path.Combine(webRootPath + SD.DefaultImagePath, imageName); using (var fileStream = new FileStream(path, FileMode.Create)) { files[0].CopyTo(fileStream); } } else { extension = SD.DefaultImageExtension; var uploads = Path.Combine(webRootPath + SD.DefaultImagePath + SD.DefaultProjectImage); System.IO.File.Copy(uploads, webRootPath + SD.DefaultImagePath + project.ProjectID.ToString() + extension); } projectFromDb.ProjectImage = SD.DefaultImagePath + project.ProjectID + extension; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { project.RenewalDate = nDate; _context.Add(project); await _context.SaveChangesAsync(); string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; var projectFromDb = await _context.Project.FindAsync(project.ProjectID); string extension; if (files.Count > 0) { extension = Path.GetExtension(files[0].FileName); string imageName = project.ProjectID + extension; string path = Path.Combine(webRootPath + SD.DefaultImagePath, imageName); using (var fileStream = new FileStream(path, FileMode.Create)) { files[0].CopyTo(fileStream); } } else { extension = SD.DefaultImageExtension; var uploads = Path.Combine(webRootPath + SD.DefaultImagePath + SD.DefaultProjectImage); System.IO.File.Copy(uploads, webRootPath + SD.DefaultImagePath + project.ProjectID.ToString() + extension); } projectFromDb.ProjectImage = SD.DefaultImagePath + project.ProjectID + extension; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { _context.Add(project); await _context.SaveChangesAsync(); string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; var projectFromDb = await _context.Project.FindAsync(project.ProjectID); string extension; if (files.Count > 0) { extension = Path.GetExtension(files[0].FileName); string imageName = project.ProjectID + extension; string path = Path.Combine(webRootPath + SD.DefaultImagePath, imageName); using (var fileStream = new FileStream(path, FileMode.Create)) { files[0].CopyTo(fileStream); } } else { extension = SD.DefaultImageExtension; var uploads = Path.Combine(webRootPath + SD.DefaultImagePath + SD.DefaultProjectImage); System.IO.File.Copy(uploads, webRootPath + SD.DefaultImagePath + project.ProjectID.ToString() + extension); } projectFromDb.ProjectImage = SD.DefaultImagePath + project.ProjectID + extension; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } ProjectClientViewModel model = new ProjectClientViewModel() { ClientList = await _context.Client.ToListAsync(), Project = project }; return(View(model)); }
public async Task <IActionResult> Edit(int id, ProjectClientViewModel model) { if (id != model.Project.ProjectID) { return(NotFound()); } if (ModelState.IsValid) { string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; var projectFromDb = await _context.Project.FindAsync(model.Project.ProjectID); if (files.Count > 0) { //Verwijder het oorspronkelijk bestand string imagePath = webRootPath + projectFromDb.ProjectImage; if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } //upload het nieuwe bestand string extension_new = Path.GetExtension(files[0].FileName); string imageName = model.Project.ProjectID + extension_new; string path = Path.Combine(webRootPath + SD.DefaultImagePath, imageName); using (var fileStream = new FileStream(path, FileMode.Create)) { files[0].CopyTo(fileStream); } projectFromDb.ProjectImage = SD.DefaultImagePath + model.Project.ProjectID + extension_new; } projectFromDb.Name = model.Project.Name; projectFromDb.ProjectDescription = model.Project.ProjectDescription; projectFromDb.StartDate = model.Project.StartDate; projectFromDb.EndDate = model.Project.EndDate; projectFromDb.Hosting = model.Project.Hosting; projectFromDb.HostingPrice = model.Project.HostingPrice; projectFromDb.RenewalDate = model.Project.RenewalDate; projectFromDb.OffertePrice = model.Project.OffertePrice; projectFromDb.TimeSpent = model.Project.TimeSpent; projectFromDb.url = model.Project.url; projectFromDb.IsActive = model.Project.IsActive; projectFromDb.AdditionalFees = model.Project.AdditionalFees; projectFromDb.TypeOfSite = model.Project.TypeOfSite; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Edit))); } ProjectClientViewModel modelVM = new ProjectClientViewModel() { ClientList = await _context.Client.ToListAsync(), Project = model.Project }; return(View(modelVM)); }