public ActionResult Create() { ViewBag.PlacesPicklist = this.GetPlacesPicklist(); TourInfoCreateViewModel model = new TourInfoCreateViewModel(); return(View(model)); }
public ActionResult CreatePost(TourInfoCreateViewModel model) { ViewBag.PlacesPicklist = this.GetPlacesPicklist(); if (ModelState.IsValid) { if (Session["token"] == null) { return(RedirectToAction("Index", "Login")); } string token = Session["token"].ToString(); // store img to IMGUR first List <string> imagesUrl = new List <string>(); if (model.Images.Count() > 0) { imagesUrl = AdminHelper.Instance.StoreImagur(model.Images); } var client = connector.Initial(); client.Timeout = -1; var request = new RestRequest("admin/tour-infos", Method.POST); request.AddHeader("Authorization", "Bearer " + token); request.AddHeader("Content-Type", "application/json"); request.AddJsonBody(new { Name = model.Name, StartPlaceId = model.StartPlace, DestinatePlaceId = model.DestinatePlace, Images = JsonConvert.SerializeObject(imagesUrl), }); IRestResponse response = client.Execute(request); if (response.IsSuccessful) { APIResultModel result = JsonConvert.DeserializeObject <APIResultModel>(response.Content); if (result.ErrorCode != 0) { ViewBag.error = result.Message; return(View()); } return(RedirectToAction("Index", "TourInfo")); } else { return(RedirectToAction("Create", "TourInfo")); } } return(View(model)); }