Exemplo n.º 1
0
 /// <summary>
 /// tao moi hoac sua
 /// </summary>
 /// <param name="shipper"></param>
 /// <returns></returns>
 public ActionResult Input(Shipper shipper)
 {
     try
     {
         // Kiểm tra dữ liệu vào
         if (string.IsNullOrEmpty(shipper.CompanyName))
         {
             ModelState.AddModelError("CompanyName", "Company Name is invalid");
         }
         if (string.IsNullOrEmpty(shipper.Phone))
         {
             shipper.Phone = "";
         }
         if (ModelState.IsValid)
         {
             // Lưu data vào DB
             if (shipper.ShipperID == 0)
             {
                 CatalogBLL.AddShipper(shipper);
             }
             else
             {
                 CatalogBLL.UpdateShipper(shipper);
             }
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace);
     }
     return(View(shipper));
 }
Exemplo n.º 2
0
 public ActionResult Input(Shipper model)
 {
     try
     {
         //TODO :Kiểm tra tính hợp lệ của dữ liệu nhập vào
         if (string.IsNullOrEmpty(model.CompanyName))
         {
             ModelState.AddModelError("CompanyName", "CompanyName expected");
         }
         if (string.IsNullOrEmpty(model.Phone))
         {
             model.Phone = "";
         }
         //TODO :Lưu dữ liệu nhập vào
         if (model.ShipperID == 0)
         {
             CatalogBLL.AddShipper(model);
         }
         else
         {
             CatalogBLL.UpdateShipper(model);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace);
         return(View(model));
     }
 }
        public ActionResult Input(Shipper model)
        {
            //TODO: Kiểm tra tính hợp lệ của dữ liệu được nhập
            if (string.IsNullOrEmpty(model.CompanyName))
            {
                ModelState.AddModelError("CompanyName", "CompanyName Expected");
            }


            if (string.IsNullOrEmpty(model.Phone))
            {
                model.Phone = "";
            }


            if (!ModelState.IsValid)
            {
                ViewBag.Title = model.ShipperID == 0 ? "Create new Shipper" : "Edit Shipper";
                return(View(model));
            }
            //TODO: Lưu dữ liệu vao DB


            if (model.ShipperID == 0)
            {
                CatalogBLL.AddShipper(model);
            }
            else
            {
                CatalogBLL.UpdateShipper(model);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public IActionResult Input(Shipper model)
        {
            try
            {
                CheckNotNull(model);
                SetEmptyNullableField(model);

                // Save data into DB
                if (model.ShipperID == 0)
                {
                    CatalogBLL.AddShipper(model);
                }
                else
                {
                    CatalogBLL.UpdateShipper(model);
                }
                return(RedirectToAction("Index"));
            }
            catch (MissingFieldException)
            {
                return(View(model));
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message + ": " + ex.StackTrace);
                return(View(model));
            }
        }
        public ActionResult Input(Shipper data)
        {
            //try
            //{
            //TODO: kiểm tr tính hợp lệ của dữ liệu
            if (string.IsNullOrEmpty(data.CompanyName))
            {
                ModelState.AddModelError("CompanyName", "CompanyName Expected");
            }
            if (string.IsNullOrEmpty(data.Phone))
            {
                ModelState.AddModelError("Phone", "Phone Expected");
            }

            if (!ModelState.IsValid)
            {
                return(View(data));
            }
            //TODO: Lưu dữ liệu vào DB
            if (data.ShipperID == 0)
            {
                CatalogBLL.AddShipper(data);
            }
            else
            {
                CatalogBLL.UpdateShipper(data);
            }
            return(RedirectToAction("Index"));
            //}
            //catch (Exception ex)
            //{
            //    ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace);
            //    return View(data);
            //}
        }
Exemplo n.º 6
0
        public ActionResult Input(Shipper model)
        {   // lam that nho them try cacht
            // : Kiểm tra tính hợp lệ của dữ liệu được nhập
            if (string.IsNullOrEmpty(model.CompanyName))
            {
                ModelState.AddModelError("CompanyName", "*");
            }

            if (string.IsNullOrEmpty(model.Phone))
            {
                ModelState.AddModelError("Phone", "*");
            }

            if (!ModelState.IsValid)
            {
                if (model.ShipperID == 0)
                {
                    ViewBag.Title = "Create new a shipper";
                    SetAlert("Add new Shipper Fail , Check again!", "warning");
                }

                else
                {
                    ViewBag.Title = "Update a shipper";
                    SetAlert("Update Shipper Fail , Check again!", "warning");
                }

                return(View(model));
            }

            //: Lưu dữ liệu vào DB
            if (model.ShipperID == 0)
            {
                SetAlert("Add new Shipper success !", "success");
                CatalogBLL.AddShipper(model);
            }
            else
            {
                SetAlert("Update Shipper success !", "success");
                CatalogBLL.UpdateShipper(model);
            }

            return(RedirectToAction("Index"));
        }