Ejemplo n.º 1
0
 public ActionResult Input(Supplier model)
 {
     try {
         if (string.IsNullOrEmpty(model.CompanyName))
         {
             ModelState.AddModelError("CompanyName", "CompanyName expected");
         }
         if (string.IsNullOrEmpty(model.ContactName))
         {
             ModelState.AddModelError("ContactName", "ContactName expected");
         }
         if (string.IsNullOrEmpty(model.ContactTitle))
         {
             ModelState.AddModelError("ContactTitle", "ContactTitle expected");
         }
         if (string.IsNullOrEmpty(model.Address))
         {
             model.Address = "";
         }
         if (string.IsNullOrEmpty(model.City))
         {
             model.City = "";
         }
         if (string.IsNullOrEmpty(model.Country))
         {
             model.Country = "";
         }
         if (string.IsNullOrEmpty(model.Fax))
         {
             model.Fax = "";
         }
         if (string.IsNullOrEmpty(model.HomePage))
         {
             model.HomePage = "";
         }
         if (string.IsNullOrEmpty(model.Phone))
         {
             model.Phone = "";
         }
         if (!ModelState.IsValid)
         {
             ViewBag.Title = model.SupplierID == 0 ? "Create new Supplier" : "Edit a Supplier";
             return(View(model));
         }
         if (model.SupplierID == 0)
         {
             CataLogBLL.AddSupplier(model);
         }
         else
         {
             CataLogBLL.UpdateSupplier(model);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Loi", ex.StackTrace);
         return(View(model));
     }
 }