public ActionResult CreateList() { if (Request.IsAuthenticated) { ListRepo rep = new ListRepo(); string userID = FindUserID(); ListVM cleanList = rep.CreateList(userID); return(View(cleanList)); } else { return(RedirectToAction("Login", "Home")); } }
public ActionResult CreateList(FormCollection formCollection) { string userID = FindUserID(); ListRepo rep = new ListRepo(); ListVM NewList = new ListVM(); if (ModelState.IsValid) { foreach (string key in formCollection.AllKeys) { switch (key) { case "ListName": NewList.ListName = formCollection[key]; break; case "ListType": NewList.ListTypeID = int.Parse(formCollection[key]); break; case "ItemCategory": NewList.ItemCategoryID = int.Parse(formCollection[key]); break; case "SuscriberGroup": NewList.SuscribergroupID = formCollection[key]; break; } } NewList.CreatorID = userID; NewList.CreationDate = DateTime.Now; if (NewList.ListName.Trim().Length < 1) { ViewBag.InputErrorMsg = "List name is required."; return(View(rep.CreateList(userID))); } else { rep.CreateList(NewList); //if (resp == false) //{ // TempData["ErrorMsg"] = "Cannot add List."; // ViewBag.ErrorMsg = "Cannot add List."; // return View(rep.CreateList(userID)); //} //else //{ // TempData["ActionMsg"] = "List Added Successfully"; // ViewBag.ActionMsg = "List Added Successfully."; return(RedirectToAction("ListManagement", "Home")); //} } } else { TempData["ErrorMsg"] = "Cannot add List."; ViewBag.ErrorMsg = "Cannot add List."; return(View(rep.CreateList(userID))); } }