}//end EditCategory public async Task <IActionResult> EditCategoryConfirm(CategoryViewModel model) { string nvm; try { if (!ModelState.IsValid) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Wrong_Values, contentRootPath); return(RedirectToAction("CategoryList", new { notification = nvm })); } if (model != null) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); var doesExist = _dbCategory.GetAll().Where(x => (x.Name == model.Name || x.LatinName.ToLower() == model.LatinName.ToLower()) && x.Id != model.Id).ToList(); if (doesExist.Count > 0) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.DuplicatedValue, contentRootPath); return(RedirectToAction("CategoryList", new { notification = nvm })); } var modifyingCategory = _dbCategory.FindById(model.Id); if (modifyingCategory != null) { modifyingCategory.Name = model.Name; modifyingCategory.LatinName = model.LatinName; modifyingCategory.Status = model.Status; modifyingCategory.ModifiedBy = modifyingCategory.ModifiedBy + $" - ویرایش شده توسط: {currentUser.UserName} ، در مورخه: {CustomizeCalendar.GregorianToPersianDateTime(DateTime.Now)} \n "; modifyingCategory.ParentId = model.ParentId; modifyingCategory.AliasName = model.AliasName; modifyingCategory.TitleAltName = model.TitleAltName; modifyingCategory.Description = model.Description; modifyingCategory.ConnectedLink = model.ConnectedLink; _dbCategory.Update(modifyingCategory); nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Update, contentRootPath); return(RedirectToAction("CategoryList", new { notification = nvm })); } } nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Update, contentRootPath); return(RedirectToAction("CategoryList", new { notification = nvm })); } catch (Exception ex) { nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Operation, contentRootPath); return(RedirectToAction("CategoryList", new { notification = nvm })); } }//end EditCategoryConfirm
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 })); } }