public ActionResult SurveyorRes(string Option) { // Let's get all states that we need for a DropDownList Status_surveyor ss = new Status_surveyor(); int aa = (int)Session["CustId"]; ss.SurvId = aa; int s; string Text = ""; if (Option == "true") { s = 1; Text = "You Are Available"; } else { s = 0; Text = "You Are Not Available"; } ss.Status = s; InsureEntities ii = new InsureEntities(); var a = ii.Status_surveyor.Where(m => m.SurvId == aa).FirstOrDefault(); ss.ID = a.ID; if (a != null) { ii.Entry(a).State = EntityState.Detached; ii.Entry(ss).State = EntityState.Modified; ii.SaveChanges(); } return(Json("" + Text, JsonRequestBehavior.AllowGet)); }
public ActionResult Surveyor_Index() { Status_surveyor ss = new Status_surveyor(); InsureEntities ii = new InsureEntities(); int id = (int)Session["CustId"]; var aa = ii.Status_surveyor.Where(m => m.SurvId == id).FirstOrDefault(); ss.Status = aa.Status; if (aa != null) { return(View(ss)); } return(View()); }
public ActionResult AddServeyor(Models.Registration user) { try { if (ModelState.IsValid) { user.RoleId = 3; Status_surveyor ss = new Status_surveyor(); using (InsureEntities db = new InsureEntities()) { if (user.UserID == 0) { var username = db.Registrations.Where(u => u.UserName == user.UserName).FirstOrDefault(); var em = db.Registrations.Where(u => u.EmailId == user.EmailId).FirstOrDefault(); if (username != null) { ViewBag.Error = "UserName already Exist"; return(View("AddServeyor", user)); } else if (em != null) { ViewBag.Error = "EmailId already Exist"; return(View("AddServeyor", user)); } else { db.Registrations.Add(user); db.SaveChanges(); ss.SurvId = user.UserID; ss.Status = 1; db.Status_surveyor.Add(ss); db.SaveChanges(); ModelState.Clear(); ViewBag.Error = "Sucessfully Submitted"; user = null; return(RedirectToAction("Dashboard", "Admin")); } } else { var username = db.Registrations.Where(u => u.UserName == user.UserName && u.UserID != user.UserID).FirstOrDefault(); var em = db.Registrations.Where(u => u.EmailId == user.EmailId && u.UserID != user.UserID).FirstOrDefault(); if (username != null) { ViewBag.Error = "UserName already Exist"; return(View("AddServeyor", user)); } else if (em != null) { ViewBag.Error = "EmailId already Exist"; return(View("AddServeyor", user)); } else { db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ModelState.Clear(); ViewBag.Error = "Sucessfully Submitted"; user = null; return(RedirectToAction("Dashboard", "Admin")); } } } } else { ModelState.AddModelError("", "Data is not correct"); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(View()); }