Exemplo n.º 1
0
        public ActionResult AcciReg()
        {
            InsureEntities db       = new InsureEntities();
            var            jsondata = (from ii in db.AccidentInfoes join reg in db.Registrations on ii.SurveyorId equals reg.UserID select new { ii.Latitude, ii.Longitude, ii.Description, ii.CustId, ii.AccidentId, reg.FirstName });

            return(Json(new { data = jsondata }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult gmadd()
        {
            InsureEntities       db       = new InsureEntities();
            List <GarrageMaster> jsondata = db.GarrageMasters.ToList <GarrageMaster>();

            return(Json(new { data = jsondata }, JsonRequestBehavior.AllowGet));
        }
        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));
        }
Exemplo n.º 4
0
        public JsonResult GetSurveyor()
        {
            InsureEntities db = new InsureEntities();

            var json = db.Registrations.Where(m => m.RoleId == 3).ToList();

            return(Json(new { data = json }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public ActionResult AddServeyor(int id = 0)
        {
            InsureEntities db       = new InsureEntities();
            var            jsondata = db.Registrations.Where(q => q.UserID == id).FirstOrDefault();

            if (jsondata == null)
            {
                jsondata = new Registration();
            }
            return(View(jsondata));
        }
Exemplo n.º 6
0
        public ActionResult DeleteGarrage(int id)
        {
            InsureEntities db       = new InsureEntities();
            var            jsondata = db.GarrageMasters.Where(q => q.Id == id).FirstOrDefault();

            if (jsondata != null)
            {
                db.GarrageMasters.Remove(jsondata);
                db.SaveChanges();
            }
            return(View(jsondata));
        }
Exemplo n.º 7
0
        public ActionResult SendEmail(checkintegration.Models.Sendmail okay, int id = 0)
        {
            InsureEntities db = new InsureEntities();
            AccidentInfo   ai = new AccidentInfo();
            Registration   rg = new Registration();

            var sid   = db.AccidentInfoes.Where(m => m.AccidentId == id).Select(m => m.SurveyorId).FirstOrDefault();
            var smail = db.Registrations.Where(m => m.UserID == sid).Single();

            var cid   = db.AccidentInfoes.Where(m => m.AccidentId == id).Select(m => m.CustId).FirstOrDefault();
            var cmail = db.Registrations.Where(m => m.UserID == cid).Single();

            MailMessage mail = new MailMessage();

            mail.To.Add(smail.EmailId);
            mail.From    = new MailAddress("*****@*****.**");
            mail.Subject = "Information about your Client";
            string Body = "Client FullName :" + cmail.FirstName + " " + cmail.LastName + "\n" + "\n Client Email ID:" + cmail.EmailId + "\n" + "\nClient Gender:" + cmail.Gender + "\n" + "\nClient Phone number:" + cmail.PhoneNumber + "\n" + "\nClient Address:" + cmail.Address + " " + cmail.Pincode;

            mail.Body       = Body;
            mail.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();

            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "jethalal004"); // Enter seders User name and password
            smtp.EnableSsl             = true;
            smtp.Send(mail);
            ViewBag.Error = "Information has been sent to registered mail id";

            mail.To.Add(cmail.EmailId);
            mail.From    = new MailAddress("*****@*****.**");
            mail.Subject = "Information about your Surveyor";
            string info = "Surveyor FullName :" + smail.FirstName + " " + smail.LastName + "\n" + "\n Surveyor Email ID:" + smail.EmailId + "\n" + "\nSurveyor Gender:" + smail.Gender + "\n" + "\nSurveyor Phone number:" + smail.PhoneNumber + "\n" + "\nSurveyor Address:" + smail.Address + " " + smail.Pincode;

            mail.Body       = info;
            mail.IsBodyHtml = true;
            // SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "jethalal004"); // Enter seders User name and password
            smtp.EnableSsl             = true;
            smtp.Send(mail);
            ViewBag.Error = "Information has been sent to registered mail id";

            return(View("View_Accident"));



            return(View());
        }
Exemplo n.º 8
0
        public ActionResult AddorEditGarrage(int id = 0)
        {
            InsureEntities db = new InsureEntities();

            if (id == 0)
            {
                return(View(new GarrageMaster()));
            }
            else
            {
                var data = db.GarrageMasters.Where(m => m.Id == id).FirstOrDefault();
                return(View(data));
            }
        }
Exemplo n.º 9
0
        public JsonResult feedbk()
        {
            InsureEntities db       = new InsureEntities();
            var            jsondata = (from x in db.FeedbackMasters
                                       select new
            {
                x.UserId,
                x.CustId,
                x.Date,
                x.feedback
            }).ToList();

            return(Json(new { data = jsondata }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        public ActionResult AddorEditSurveyor(int id = 0)
        {
            InsureEntities db = new InsureEntities();

            if (id == 0)
            {
                return(View(new Registration()));
            }
            else
            {
                var data = db.Registrations.Where(m => m.UserID == id).FirstOrDefault();
                return(View(data));
            }
        }
Exemplo n.º 11
0
        public ActionResult UploadReport(int id = 0)
        {
            InsureEntities db = new InsureEntities();

            if (id == 0)
            {
                return(View());
            }
            else
            {
                var data = db.AccidentInfoes.Where(m => m.AccidentId == id).FirstOrDefault();
                return(View(data));
            }
        }
Exemplo n.º 12
0
        public ActionResult UploadReport(FormCollection fc, HttpPostedFileBase file)
        {
            InsureEntities db = new InsureEntities();
            ReportMst      rm = new ReportMst();
            var            id = Convert.ToInt32(fc[0]);

            rm.AccidentId = id;
            rm.ReportType = fc[1];
            var sid  = db.AccidentInfoes.Where(m => m.AccidentId == id).Select(m => m.SurveyorId).FirstOrDefault();
            var name = db.Registrations.Where(m => m.UserID == sid).Select(m => m.EmailId).FirstOrDefault();


            rm.SurveyorId = sid;
            string h = "";

            // E:\project_shown\checkintegration\checkintegration\Content\FilePath\
            try
            {
                if (file != null)
                {
                    string path = Path.Combine(Server.MapPath("~/Content/FilePath/"), Path.GetFileName(file.FileName));
                    string n    = Path.GetFileName(file.FileName);
                    file.SaveAs(path);
                    rm.FilePath = "~/Content/FilePath/" + n;
                    db.ReportMsts.Add(rm);
                    db.SaveChanges();
                    //return Json(new { data = "fdsdsass" +h}, JsonRequestBehavior.AllowGet);
                    return(RedirectToAction("View_Accident", "Admin"));
                }


                return(Json(new { data = "Faillll" + h }, JsonRequestBehavior.AllowGet));
            }
            catch (DbEntityValidationException e)
            {
                string ms = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    ms += "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)
                    {
                        ms += "- Property: \"{0}\", Error: \"{1}\"" +
                              ve.PropertyName + ve.ErrorMessage;
                    }
                }
                return(Json(new { success = false, message = ms }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 13
0
        public ActionResult DeleteServeyor(int id)
        {
            //if( Session["UserId"] == null)
            //{
            //    return RedirectToAction("Login","Home");
            //}
            InsureEntities db       = new InsureEntities();
            var            jsondata = db.Registrations.Where(q => q.UserID == id).FirstOrDefault();

            if (jsondata != null)
            {
                db.Registrations.Remove(jsondata);
                db.SaveChanges();
            }
            return(View(jsondata));
        }
Exemplo n.º 14
0
 public ActionResult ForgotPassword(checkintegration.Models.Sendmail okay)
 {
     try
     {
         if (ModelState.IsValid)
         {
             InsureEntities db    = new InsureEntities();
             var            email = db.Registrations.Where(a => a.EmailId == okay.To).FirstOrDefault();
             if (email != null)
             {
                 var         pass = db.Registrations.Where(a => a.EmailId == okay.To).Select(a => new { Password = a.Password }).Single();
                 MailMessage mail = new MailMessage();
                 mail.To.Add(okay.To);
                 mail.From    = new MailAddress("*****@*****.**");
                 mail.Subject = "Forgot Password";
                 string Body = "Your Password is:" + pass.Password;
                 mail.Body       = Body;
                 mail.IsBodyHtml = true;
                 SmtpClient smtp = new SmtpClient();
                 smtp.Host = "smtp.gmail.com";
                 smtp.Port = 587;
                 smtp.UseDefaultCredentials = false;
                 smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "jethalal004"); // Enter seders User name and password
                 smtp.EnableSsl             = true;
                 smtp.Send(mail);
                 ViewBag.Error = "Password has been sent to registered mail id";
                 return(View("LogIn"));
             }
             else
             {
                 ViewBag.Error = "Email not Found";
                 return(View(okay));
             }
         }
         else
         {
             ViewBag.Error = "Some Error Occured";
             return(View(okay));
         }
     }
     catch (Exception e)
     {
         ViewBag.Error = "Error Occured";
         return(View("ForgotPassword", okay));
     }
 }
        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());
        }
Exemplo n.º 16
0
        public ActionResult AddorEditGarrage(GarrageMaster rm)
        {
            try
            {
                InsureEntities db   = new InsureEntities();
                var            data = db.GarrageMasters.Where(m => m.Id == rm.Id).FirstOrDefault();
                if (data != null)
                {
                    //rm.Id = data.Id;
                    rm.Name        = data.Name;
                    rm.Address     = data.Address;
                    rm.PhoneNo     = data.PhoneNo;
                    rm.OwnerName   = data.OwnerName;
                    rm.Description = data.Description;
                    rm.IsAuth      = data.IsAuth;
                    rm.CreatedBy   = data.CreatedBy;

                    db.Entry(data).State = EntityState.Detached;
                    db.Entry(rm).State   = EntityState.Modified;
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, message = "Updation Error" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (DbEntityValidationException e)
            {
                string ms = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    ms += "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)
                    {
                        ms += "- Property: \"{0}\", Error: \"{1}\"" +
                              ve.PropertyName + ve.ErrorMessage;
                    }
                }
                return(Json(new { success = false, message = ms }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 17
0
 public ActionResult AddorEditSurveyor(Registration rm)
 {
     try
     {
         InsureEntities db   = new InsureEntities();
         var            data = db.Registrations.Where(m => m.UserID == rm.UserID).FirstOrDefault();
         if (data != null)
         {
             rm.UserName           = data.UserName;
             rm.ConfirmPassword    = data.ConfirmPassword;
             rm.Gender             = data.Gender;
             rm.NewConfirmPassword = data.NewConfirmPassword;
             rm.Password           = data.Password;
             rm.Pincode            = data.Pincode;
             rm.RoleId             = data.RoleId;
             rm.Address            = data.Address;
             db.Entry(data).State  = EntityState.Detached;
             db.Entry(rm).State    = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { success = false, message = "Updation Error" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (DbEntityValidationException e)
     {
         string ms = "";
         foreach (var eve in e.EntityValidationErrors)
         {
             ms += "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)
             {
                 ms += "- Property: \"{0}\", Error: \"{1}\"" +
                       ve.PropertyName + ve.ErrorMessage;
             }
         }
         return(Json(new { success = false, message = ms }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 18
0
 public ActionResult AddGarrage(Models.GarrageMaster gm)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (InsureEntities db = new InsureEntities())
             {
                 db.GarrageMasters.Add(gm);
                 db.SaveChanges();
                 ModelState.Clear();
                 ViewBag.Error = "Sucessfully Submitted";
                 gm            = 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());
 }
Exemplo n.º 19
0
        public ActionResult Register(Models.Registration user, FormCollection fc)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    user.RoleId = 2;

                    using (InsureEntities db = new InsureEntities())
                    {
                        /*  var newUser = db.Registrations.Create();
                         * // newUser.UserID = user.UserID;
                         * newUser.FirstName = user.FirstName;
                         * newUser.LastName = user.LastName;
                         * newUser.UserName = user.UserName;
                         * newUser.EmailId = user.EmailId;
                         * newUser.Password = user.Password;
                         * newUser.ConfirmPassword = user.ConfirmPassword;
                         * newUser.Gender = user.Gender;
                         * // newUser.RoleId = user.RoleId;
                         * newUser.Address = user.Address;
                         * newUser.Pincode = user.Pincode;
                         * newUser.PhoneNumber = user.PhoneNumber;
                         */
                        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("Register", user));
                        }

                        else if (em != null)
                        {
                            ViewBag.Error = "EmailId already Exist";
                            return(View("Register", user));
                        }
                        else
                        {
                            //user.FirstName
                            user.Gender = fc["type"].ToString();
                            db.Registrations.Add(user);
                            db.SaveChanges();
                            ModelState.Clear();
                            Session["UserID"] = user.UserID;
                            ViewBag.Error     = "Sucessfully Submitted";
                            user = null;
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }
                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());
        }
Exemplo n.º 20
0
        // string OldPassword, string NewPassword, string NewConfirmPassword,string UserID
        public ActionResult Change_Password(Models.Registration user)
        {
            InsureEntities db = new InsureEntities();
            //LoginMst obj = new LoginMst();
            var lst = db.Registrations.Where(P => P.EmailId == user.EmailId && P.Password == user.Password).SingleOrDefault();
            var ls  = db.Registrations.Where(P => P.Password == user.NewPassword).SingleOrDefault();

            //bool IsUserExist = db.LoginMsts.Where(P => P.SrNo == UserID && P.Password==OldPassword).Any();
            if (lst != null)
            {
                ViewBag.message = "Changing done";
                if (ls != null)
                {
                    ViewBag.Error = "New Password already Exist";
                    return(RedirectToAction("Change_Password", "Home"));
                }
                else
                {
                    var ab = db.Registrations.Where(P => P.EmailId == user.EmailId && P.Password == user.Password).SingleOrDefault();
                    //  var cd = db.Registrations.Where(P => P.Password == user.NewPassword).SingleOrDefault();
                    Registration rg = new Registration();
                    rg.UserID          = ab.UserID;
                    rg.FirstName       = ab.FirstName;
                    rg.LastName        = ab.LastName;
                    rg.UserName        = ab.UserName;
                    rg.EmailId         = ab.EmailId;
                    rg.Password        = user.NewPassword;
                    rg.ConfirmPassword = user.NewConfirmPassword;
                    rg.Gender          = ab.Gender;
                    rg.RoleId          = ab.RoleId;
                    rg.Address         = ab.Address;
                    rg.Pincode         = ab.Pincode;
                    rg.PhoneNumber     = ab.PhoneNumber;

                    db.Entry(ab).State = EntityState.Detached;
                    db.Entry(rg).State = EntityState.Modified;

                    /* lst.Password = user.NewPassword;
                     * lst.ConfirmPassword = user.NewConfirmPassword;*/

                    ViewBag.message = "Changing password successflly done";
                    // db.Registrations.Add(user);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var entityValidationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in entityValidationErrors.ValidationErrors)
                            {
                                Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                            }
                        }
                    }

                    /*  System.Diagnostics.Debug.Write("Hello via Debug!"+lst.Password);
                     * return RedirectToAction("Change_Password", "Home");*/
                    return(Json(ViewBag.message));
                }
                //return 0;
            }
            else
            {
                ViewBag.Error = "Email Id or Password is wrong!!";
                return(RedirectToAction("Change_Password", "Home"));;
            }

            /*catch (DbEntityValidationException ex)
             * {
             *  foreach (var entityValidationErrors in ex.EntityValidationErrors)
             *  {
             *      foreach (var validationError in entityValidationErrors.ValidationErrors)
             *      {
             *          Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
             *      }
             *  }
             * }*/
            return(View());
        }
Exemplo n.º 21
0
        public ActionResult ContactUs(Models.FeedbackMaster fm)
        {
            try
            {
                fm.Date   = DateTime.Now;
                fm.CustId = (System.Int32)Session["UserId"];
                if (ModelState.IsValid)
                {
                    using (InsureEntities db = new InsureEntities())
                    {
                        /* var newUser = db.FeedbackMasters.Create();
                         * newUser.CustId = fm.UserId;
                         * //  newUser.Date = fm.Date;
                         * newUser.feedback = fm.feedback;*/

                        db.FeedbackMasters.Add(fm);
                        db.SaveChanges();
                        ModelState.Clear();
                        //Session["UserID"] = user.UserID;
                        ViewBag.Error = "Sucessfully Submitted";
                        fm            = null;
                        return(RedirectToAction("Login", "Home"));
                    }
                }
                else
                {
                    /* using (InsureEntities2 db = new InsureEntities2())
                     * {
                     *
                     *   db.FeedbackMasters.Add(fm);
                     *   db.SaveChanges();
                     *   ModelState.Clear();
                     *   //Session["UserID"] = user.UserID;
                     *   ViewBag.Error = "Sucessfully Submitted";
                     *   fm = null;
                     *   return RedirectToAction("Login", "Home");
                     *
                     *
                     * }
                     */
                    // ModelState.AddModelError("", "Data is not correct");
                    return(RedirectToAction("Register", "Home"));
                }
            }
            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);
                    }
                }
                return(View());
                // throw;
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(View());
            }
        }
Exemplo n.º 22
0
        public ActionResult Accident_Register(Models.AccidentInfo ss)
        {
            try
            {
                // Registration rg=new Registration();
                ss.CustId = (int)Session["UserId"];
                InsureEntities db1  = new InsureEntities();
                var            a    = db1.Status_surveyor.Where(m => m.Status == 1).Select(m => m.SurvId).ToArray();
                var            rand = new Random();
                var            sid  = a[rand.Next(a.Length)];

                ss.SurveyorId = sid;
                ss.Status     = 0;

                if (ModelState.IsValid)
                {
                    using (InsureEntities db = new InsureEntities())
                    {
                        db.AccidentInfoes.Add(ss);
                        db.SaveChanges();
                        ModelState.Clear();
                        //Session["UserID"] = user.UserID;
                        ViewBag.Error = "Sucessfully Submitted";
                        ss            = null;
                        return(RedirectToAction("Homepage", "Home"));
                    }
                }
                else
                {
                    /* using (InsureEntities2 db = new InsureEntities2())
                     * {
                     *
                     *   db.FeedbackMasters.Add(fm);
                     *   db.SaveChanges();
                     *   ModelState.Clear();
                     *   //Session["UserID"] = user.UserID;
                     *   ViewBag.Error = "Sucessfully Submitted";
                     *   fm = null;
                     *   return RedirectToAction("Login", "Home");
                     *
                     *
                     * }
                     */
                    // ModelState.AddModelError("", "Data is not correct");
                    return(RedirectToAction("Register", "Home"));
                }
            }
            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);
                    }
                }
                return(View());
                // throw;
            }

            /* catch(Exception e)
             * {
             *   Console.Write(e);
             *   return View();
             *
             * }*/
        }
Exemplo n.º 23
0
        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());
        }