public ActionResult Create(ChoiceModel choiceModel) { try { if (choiceModel.Name != null) { if (ModelState.IsValid) { char delimiter = ','; var detailsList = choiceModel.DetailsList.Split(delimiter).ToList(); var ListDetails = new List<DetailModel>(); foreach (var item in detailsList) { if (item.Length > 0) { ListDetails.Add(new DetailModel() { Name = _details.Find(x => x.Name == item).Name, DetailId = _details.Find(x => x.Name == item).DetailId }); } } var newchoice = new ChoiceModel() { ChoiceId = choiceModel.ChoiceId, Category = choiceModel.Category, CategoryId = choiceModel.CategoryId, Name = choiceModel.Name, Details = ListDetails, }; var choice = Newtonsoft.Json.JsonConvert.SerializeObject(newchoice); if (choice != null) { var response = _handler.Post(choice); if (response.StatusCode == 201) { _log.Debug("Answer from Web API: " + response.StatusCode + response.StatusDescription); } } } return RedirectToAction("Index"); } _log.Debug("No 'Navn' added to new choice or no detail was selected, exiting"); return RedirectToAction("Index"); } catch(Exception ex) { _log.Exception(ex.Message + ex.InnerException); return RedirectToAction("Index"); } }
public ActionResult AddChoice(ChoiceModel choiceModel, string cat) { //try //{ // if (choiceModel.Name != null) // { // if (ModelState.IsValid) // { // var newChoice = new Choice // { // ChoiceId = Guid.NewGuid(), // CategoryId = choiceModel.CategoryId, // Name = choiceModel.Name // }; // _log.Debug("New Choice added: " + newChoice.Name); // } // return RedirectToAction("AddChoice"); // } // _log.Debug("No 'Navn' added to new choice, exiting"); // return RedirectToAction("AddChoice"); //} //catch (Exception ex) //{ // _log.Exception(ex.Message); // return RedirectToAction("AddChoice"); //} return View(); }