예제 #1
0
        /// <summary>
        /// this function adds a new delivery to the database
        /// </summary>
        /// <returns>The NewDelivery view</returns>
        public ActionResult AddDelievery()
        {
            if (Session["User"] == null)
            {
                TempData["Result"] = true;
                return(RedirectToAction("", ""));
            }
            DelieveryVM  cvm          = new DelieveryVM();
            Delievery    objDelievery = new Delievery();
            DelieveryDal dal          = new DelieveryDal();

            objDelievery.userName      = Session["User"].ToString();
            objDelievery.address       = Request.Form["Delievery.address"];
            objDelievery.phone         = Request.Form["Delievery.phone"];
            objDelievery.delieveryName = Request.Form["Delievery.delieveryName"];
            if (ModelState.IsValid)
            {
                dal.Delieveries.Add(objDelievery);
                dal.SaveChanges();
                cvm.Delievery = new Delievery();
            }
            else
            {
                return(View("NewDelievery"));
            }
            cvm.Delieveries   = dal.Delieveries.ToList <Delievery>();
            ViewBag.TheResult = true;
            return(View("NewDelievery", cvm));
        }
예제 #2
0
        /// <summary>
        /// the function searches a delivery by the name or id according to the user's choice
        /// </summary>
        public ActionResult SearchDelievery()
        {
            if (Session["User"] == null)
            {
                TempData["Result"] = true;
                return(RedirectToAction("", ""));
            }
            DelieveryDal dal = new DelieveryDal();
            string       searchValue;
            DelieveryVM  cvm = new DelieveryVM();

            searchValue = Session["User"].ToString();
            List <Delievery> objDelieveries =
                (from x in dal.Delieveries
                 where x.userName.Equals(searchValue)
                 select x).ToList <Delievery>();

            if (objDelieveries != null)
            {
                cvm.Delieveries = objDelieveries;
                return(View("SearchDelievery", cvm));
            }
            ViewBag.TheResult = true;
            return(View("SearchDelievery"));
        }
예제 #3
0
        /// <summary>
        /// The function deletes a delivery by the id that the user entered
        /// </summary>
        public ActionResult DeleteDelievery()
        {
            if (Session["Manager"] == null)
            {
                TempData["Result"] = true;
                return(RedirectToAction("", ""));
            }
            DelieveryDal dal   = new DelieveryDal();
            DelieveryVM  cvm   = new DelieveryVM();
            string       value = Request.Form["DelieveryID"];

            if (value != null)
            {
                if (value != "")
                {
                    int       id             = int.Parse(value);
                    Delievery objDelieveries =
                        (from x in dal.Delieveries
                         where x.delieveryID.Equals(id)
                         select x).FirstOrDefault();
                    if (objDelieveries == null)
                    {
                        ViewBag.TheResult = true;
                        return(View("DeleteDelievery"));
                    }
                    dal.Delieveries.Remove(objDelieveries);
                    dal.SaveChanges();
                }
            }
            return(View("DeleteDelievery"));
        }
예제 #4
0
        /// <summary>
        /// The function searches a delivery by the id or by name according to the user's choice
        /// </summary>

        public ActionResult SearchDelievery()
        {
            if (Session["Manager"] == null)
            {
                TempData["Result"] = true;
                return(RedirectToAction("", ""));
            }
            DelieveryDal dal = new DelieveryDal();
            string       searchValue;
            int          n;
            DelieveryVM  cvm = new DelieveryVM();

            searchValue = Request.Form["DelieveryNameOrID"];
            string radio = Request.Form["optradio"];

            if (searchValue != null)
            {
                if (radio != null)
                {
                    if (radio.Equals("delieveryID"))
                    {
                        if (searchValue != "" && int.TryParse(searchValue, out n))
                        {
                            int       id             = int.Parse(searchValue);
                            Delievery objDelieveries =
                                (from x in dal.Delieveries
                                 where x.delieveryID.Equals(id)
                                 select x).FirstOrDefault();
                            if (objDelieveries != null)
                            {
                                cvm.Delievery = objDelieveries;

                                return(View("SearchDelievery", cvm));
                            }
                        }
                    }
                    else if (radio.Equals("delieveryName"))
                    {
                        if (searchValue != "")
                        {
                            Delievery objDelieveries =
                                (from x in dal.Delieveries
                                 where x.delieveryName.Equals(searchValue)
                                 select x).FirstOrDefault();
                            if (objDelieveries != null)
                            {
                                cvm.Delievery = objDelieveries;

                                return(View("SearchDelievery", cvm));
                            }
                        }
                    }
                }
                ViewBag.TheResult = true;
            }
            return(View("SearchDelievery"));
        }
예제 #5
0
        /// <summary>
        /// In this function we open a connection to the database and the function returns the NewDelivery view
        /// </summary>
        public ActionResult NewDelievery()
        {
            if (Session["User"] == null)
            {
                TempData["Result"] = true;
                return(RedirectToAction("", ""));
            }
            DelieveryDal dal = new DelieveryDal();
            DelieveryVM  cvm = new DelieveryVM();

            cvm.Delievery   = new Delievery();
            cvm.Delieveries = dal.Delieveries.ToList <Delievery>();
            return(View(cvm));
        }