public ActionResult HomeDel(HomeDelivery home)
        {
            try
            {
                HomeDelivery ff = new HomeDelivery();
                ff.Address    = home.Address;
                ff.CustomerId = Convert.ToInt32(Session["UserId"]);
                ff.Contact    = home.Contact;
                dd.HomeDeliveries.Add(ff);
                dd.SaveChanges();
                TempData["Message"] = "Dear Customer, Ride will be at your place shortly";

                return(View());
            }
            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());
        }
        public ActionResult EditPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var ToUpdate = dd.Categories.Find(id);

            if (TryUpdateModel(ToUpdate, "",
                               new string[] { "Name" }))
            {
                try
                {
                    dd.SaveChanges();

                    return(View());
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }

            return(View(ToUpdate));
        }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Contact,Address,Designation,Salary")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Esempio n. 4
0
        public ActionResult CreateCustomer(CustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!db.Customers.Any(x => x.Email == model.Email))
                {
                    Customer cust = new Customer();
                    cust.Email     = model.Email;
                    cust.Password  = model.Password;
                    cust.FirstName = model.FirstName;
                    cust.LastName  = model.LastName;
                    cust.Address   = model.Address;
                    cust.Contact   = model.Contact;
                    cust.SQuestion = model.SQuestion;
                    cust.SAnswer   = model.Address;
                    db.Customers.Add(cust);
                    db.SaveChanges();

                    TempData["Message"] = "Registered Sucessfully";
                    ModelState.Clear();
                    return(View(model));
                }

                else
                {
                    TempData["Message"] = "Email, already exists!";
                    ModelState.Clear();
                    return(View(model));
                }
            }
            model.Email     = "";
            model.FirstName = "";
            model.LastName  = "";
            model.Password  = "";
            model.Contact   = "";
            model.Address   = "";
            model.SQuestion = "";
            model.SAnswer   = "";
            return(View(model));
        }