Esempio n. 1
0
 public ActionResult Create()
 {
     var model = new ShipmentBatch();
     ParseQueryString(Request, model, true);
     LoadLists(model);
     return View(model);
 }
Esempio n. 2
0
        public ActionResult Create(ShipmentBatch model)
        {
            LoadLists(model);
            Validate(model);

            if (ModelState.IsValid)
            {
                data.Insert(model.CreateShipmentCollection(), (Session["LoggedInUser"] as user).id);
                TempData["SuccessMessage"] = string.Format("Shipment was created.");

                if (model.Redirect == "title")
                    return RedirectToAction("Edit", "Title", new { id = model.TitleId });
                if (model.Redirect == "contact")
                    return RedirectToAction("Edit", "Contact", new { id = model.ContactId });
                return RedirectToAction("Search");
            }

            return View(model);
        }
Esempio n. 3
0
 private void ParseQueryString(HttpRequestBase Request, ShipmentBatch model, bool isCreate)
 {
     model.Redirect = string.Empty;
     if (!string.IsNullOrEmpty(Request.QueryString["title"]))
     {
         model.Redirect = "title";
         if (isCreate)
         {
             int titleId = Convert.ToInt32(Request.QueryString["title"]);
             model.TitleId = titleId;
             model.SelectedTitles.Add(titleId);
             model.TitleName = reviewData.GetTitleDisplayNameById(model.TitleId);
         }
     }
     else if (!string.IsNullOrEmpty(Request.QueryString["contact"]))
     {
         model.Redirect = "contact";
         if (isCreate)
         {
             int contactId = Convert.ToInt32(Request.QueryString["contact"]);
             model.ContactId = contactId;
             model.SelectedContacts.Add(contactId);
             model.ContactName = reviewData.GetContactDisplayNameById(model.ContactId);
         }
     }
 }
Esempio n. 4
0
        private void Validate(ShipmentBatch model)
        {
            // Make sure a contact and title was seelected
            if (model.SelectedContacts.Count < 1)
                ModelState.AddModelError("SelectedContacts", "Please select a valid Contact from the auto complete choices");
            if (model.SelectedTitles.Count < 1)
                ModelState.AddModelError("SelectedTitles", "Please select a valid Title from the auto complete choices");

            // Make sure each contact and title has a non-zero ID
            foreach (int contactId in model.SelectedContacts)
            {
                if (contactId < 1)
                    ModelState.AddModelError("SelectedContacts", "Please select a valid Contact from the auto complete choices");
            }
            foreach (int titleId in model.SelectedTitles)
            {
                if (titleId < 1)
                    ModelState.AddModelError("SelectedTitles", "Please select a valid Title from the auto complete choices");
            }

            if (!ModelState.IsValid)
                ModelState.AddModelError(string.Empty, "Please fix the errors below.");
        }
Esempio n. 5
0
 private void LoadLists(ShipmentBatch model)
 {
     var titleId = model.TitleId.ToString();
     var titleName = string.IsNullOrEmpty(model.TitleName) ? "Search for a Title" : model.TitleName;
     var contactId = model.ContactId.ToString();
     var contactName = string.IsNullOrEmpty(model.ContactName) ? "Search for a Contact" : model.ContactName;
     var contacts = new List<SelectListItem> { new SelectListItem { Text = contactName, Value = contactId } };
     var titles = new List<SelectListItem> { new SelectListItem { Text = titleName, Value = titleId } };
     model.Contacts = new MultiSelectList(contacts, "Value", "Text", null);
     model.Titles = new MultiSelectList(titles, "Value", "Text", null);
 }