public ActionResult SaveInput(Guid?id) { Campaign campaign = Db.Campaigns .Include(x => x.Assets) .FirstOrDefault(x => x.Id == id); if (campaign == null) { TempData["Error"] = "Campaign not found."; return(RedirectToAction("View", "OpenModel", new { id = id })); } var vm = new OpenModelInputVm() { Id = campaign.Id.ToString(), OrderNumber = campaign.OrderNumber, OpenModelLinksFile = campaign.Assets.OpenModelLinksFile, OpenModelImageFile = campaign.Assets.OpenModelImageFile, SFDClientId = campaign.Assets.SFDClientId.ToString() }; // Lists ViewBag.SfidClientCampaigns = new SelectList(SfidClientCampaigns, "Value", "Text", vm.SFDClientId); return(View(vm)); }
public ActionResult SaveInput(OpenModelInputVm vm) { if (ModelState.IsValid) { Campaign campaign = Db.Campaigns .Include(x => x.Assets) .FirstOrDefault(x => x.Id.ToString() == vm.Id); campaign.Assets.OpenModelLinksFile = vm.OpenModelLinksFile; campaign.Assets.OpenModelImageFile = vm.OpenModelImageFile; if (!string.IsNullOrEmpty(vm.SFDClientId)) { campaign.Assets.SFDClientId = int.Parse(vm.SFDClientId); } if (!string.IsNullOrEmpty(campaign.Assets.OpenModelLinksFile)) { string filePath = Path.Combine(UploadPath, campaign.Assets.OpenModelLinksFile); S3FileManager.Download(campaign.Assets.OpenModelLinksFile, filePath); List <string> links = CsvReader.ReadCsv(filePath); campaign.Assets.OpenModelLinksCount = links.Count; } Db.SaveChanges(); TempData["Success"] = "Reporting Model Input data saved successfully!"; return(RedirectToAction("View", "OpenModel", new { id = vm.Id })); } else { var errorList = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); TempData["Error"] = "There is error in saving data." + string.Join("<br/>", errorList); } return(View("OpenModelInput", vm)); }