[HttpPost]//Registration public ActionResult Create(EmailManageModel tmi) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); int UserID = Convert.ToInt32(Session["UserId"]); //MailID Details validation string name = tmi.Email.EmployeeName.ToString(); string emailid = tmi.Email.EmailID.ToString(); string contactNo = tmi.Email.EmployeeContactNum.ToString(); var doesTheseExists = db.tblmailids.Where(m => m.IsDeleted == 0 && (m.EmployeeName == name || m.EmailID == emailid || m.EmployeeContactNum == contactNo)).ToList(); if (doesTheseExists.Count == 0) { tmi.Email.IsDeleted = 0; tmi.Email.CreatedBy = UserID; tmi.Email.CreatedOn = DateTime.Now; db.tblmailids.Add(tmi.Email); db.SaveChanges(); return(RedirectToAction("Index")); } else { TempData["toaster_error"] = null; var doesNameExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.EmployeeName == name).ToList(); if (doesNameExists.Count > 0) { TempData["toaster_error"] += "Duplicate Name. "; } var doesMailIdExists = db.tblmailids.Where(m => m.EmailID == emailid).ToList(); if (doesMailIdExists.Count > 0) { TempData["toaster_error"] += " Duplicate Email ID. "; } var doesCnoExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.EmployeeContactNum == contactNo).ToList(); if (doesCnoExists.Count > 0) { TempData["toaster_error"] += " Duplicate Contact Number. "; } //var email = db.tblmailids.Where(m => m.IsDeleted == 0).FirstOrDefault(); return(Redirect("Index")); } }
public ActionResult Index() { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; //String Username = Session["Username"].ToString(); EmailManageModel email = new EmailManageModel(); tblmailid em = new tblmailid(); email.Email = em; email.EmailList = db.tblmailids.Where(m => m.IsDeleted == 0).ToList(); //var mailData = db.masteremailmanage_tbl.Where(m => m.IsDeleted == 0).ToList(); return(View(email)); }
public ActionResult Edit(EmailManageModel tmi) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); int UserID = Convert.ToInt32(Session["UserID"]); //MailID details validation string name = tmi.Email.EmployeeName.ToString(); string emailid = tmi.Email.EmailID.ToString(); string contactNo = tmi.Email.EmployeeContactNum.ToString(); int MailIDDetailsID = tmi.Email.MailIDsID; var doesTheseExists = db.tblmailids.Where(m => m.IsDeleted == 0 && (m.EmployeeName == name || m.EmailID == emailid || m.EmployeeContactNum == contactNo) && m.MailIDsID != MailIDDetailsID).ToList(); if (doesTheseExists.Count == 0) { var MailId = db.tblmailids.Find(tmi.Email.MailIDsID); MailId.EmailID = tmi.Email.EmailID; MailId.EmployeeName = tmi.Email.EmployeeName; MailId.EmployeeContactNum = tmi.Email.EmployeeContactNum; MailId.ModifiedBy = 1; MailId.ModifiedOn = DateTime.Now; db.Entry(MailId).State = EntityState.Modified; db.SaveChanges(); #region Active Log Code //tblmachinecategory OldData = db.tblmachinecategories.Find(tblmc.ID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblmachinecategory>(OldData, tblmc); //ICollection<tblmachinecategory> c = FullData as ICollection<tblmachinecategory>; //int Count = c.Count; //if (Count != 0) //{ // string CompleteModificationdetail = null; // for (int i = 0; i < Count; i++) // { // CompleteModificationdetail = CompleteModificationdetail + "-" + FullData.Take(i).ToArray(); // } // Action = "Edit"; // ActiveLogStorage Obj = new ActiveLogStorage(); // Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //} #endregion //End Active Log } else { TempData["toaster_error"] = null; var doesNameExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.EmployeeName == name && m.MailIDsID != MailIDDetailsID).ToList(); if (doesNameExists.Count > 0) { TempData["toaster_error"] += "Duplicate Name. "; } var doesMailIdExists = db.tblmailids.Where(m => m.EmailID == emailid && m.MailIDsID != MailIDDetailsID).ToList(); if (doesMailIdExists.Count > 0) { TempData["toaster_error"] += " Duplicate Email ID. "; } var doesCnoExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.EmployeeContactNum == contactNo && m.MailIDsID != MailIDDetailsID).ToList(); if (doesCnoExists.Count > 0) { TempData["toaster_error"] += " Duplicate Contact Number. "; } return(View(tmi)); } return(RedirectToAction("Index")); }