예제 #1
0
        public IActionResult AddShipper(AddShiperModel model)
        {
            if (!ModelState.IsValid)
            {
                this.ViewBag.Error = "The input data is not valid !!!";
                return(View(model));
            }


            var result = this.adminServices.AddShupper(model);

            if (!result)
            {
                TempData["_Message"] = "The shipper is not add in database !!! ";

                return(View(model));
            }

            this.TempData["_Message"] = "The shipper is add successful";

            return(RedirectToAction(nameof(AddShipper)));
        }
예제 #2
0
        public bool AddShupper(AddShiperModel addShiper)
        {
            var result = this.db.Shippers.Where(s => s.NameOfShipper == addShiper.NameOfShipper || s.Phone == addShiper.Phone).FirstOrDefault();

            if (result != null)
            {
                return(false);
            }
            var shipper = new Shipper()
            {
                NameOfShipper = addShiper.NameOfShipper,
                Phone         = addShiper.Phone,
                //ShopingId = 1
            };

            if (shipper == null)
            {
                return(false);
            }

            this.db.Shippers.Add(shipper);
            this.db.SaveChanges();
            return(true);
        }