public ActionResult MessageGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Messages item) { var model = unitOfWork.MessagesRepo.Fetch().Where(m => m.MessageTo == UserId); if (ModelState.IsValid) { try { // Insert here a code to update the item in your model if (item.IsMail == true) { userManager.SendEmail(item.MessageFrom, item.Subject, item.Body); } item.MessageTo = item.MessageFrom; item.MessageFrom = UserId; item.DateCreated = DateTime.Now; unitOfWork.MessagesRepo.Insert(item); unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_MessageGridViewPartial", model.ToList())); }
public ActionResult MessageGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Messages item) { var model = unitOfWork.MessagesRepo.Fetch().Where(m => m.MessageTo == UserId); model = model.Where(m => m.MessageTo == UserId); if (ModelState.IsValid) { try { // Insert here a code to insert the new item in your model if (Session["UploadedFile"] is UploadedFile uploaded) { item.FileName = uploaded.FileName; item.Files = uploaded.FileBytes; item.MimeType = uploaded.ContentType; } item.MessageFrom = User.Identity.IsAuthenticated ? UserId : item.MessageFrom; item.DateCreated = DateTime.Now; item.CreatedBy = User.Identity.IsAuthenticated ? UserId : item.MessageFrom; if (!User.Identity.IsAuthenticated) { foreach (var i in unitOfWork.UsersRepo.Fetch(m => m.UserRoles.Any(x => x.Name == "Administrator" || x.Name == "Admin"))) { item.MessageTo = i.Id; unitOfWork.MessagesRepo.Insert(item); } } else { item.MessageTo = item.MessageFrom; unitOfWork.MessagesRepo.Insert(item); } unitOfWork.Save(); Response.Cookies.Add(new HttpCookie("Email", item.MessageFrom) { }); if (item.IsMail == true) { userManager.SendEmail(item.MessageTo, item.Subject, item.Body); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_MessageGridViewPartial", model.ToList())); }
public ActionResult MessageGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Messages item) { var model = unitOfWork.MessagesRepo.Fetch().Where(m => m.MessageTo == UserId); model = model.Where(m => m.MessageTo == UserId); if (ModelState.IsValid) { try { // Insert here a code to insert the new item in your model if (Session["UploadedFile"] is UploadedFile uploaded) { item.FileName = uploaded.FileName; item.Files = uploaded.FileBytes; item.MimeType = uploaded.ContentType; } item.MessageFrom = UserId; item.DateCreated = DateTime.Now; unitOfWork.MessagesRepo.Insert(item); unitOfWork.Save(); if (item.IsMail == true) { userManager.SendEmail(item.MessageTo, item.Subject, item.Body); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_MessageGridViewPartial", model.ToList())); }