public ActionResult Create([Bind(Include = "Name,StrapLine,Description,Image,ImageLocation,Website,CampaignStartDateTime,CampaignEndDateTime,LocationName,LocationAddressLine1,LocationAddressLine2,LocationAddressLine3,LocationAddressTownCity,LocationAddressCounty,LocationAddressPostcode,LocationTelephoneNumber,LocationEmail,LocationContactName,CallingAction,CallingController")] CampaignAddView campaign, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/images"), pic); // file is uploaded //file.SaveAs(path); //campaign.ImageLocation = path; // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); campaign.Image = array; } } CampaignHelpers.CreateCampaignFromCampaignAddView(campaign, User); return(RedirectToAction(campaign.CallingAction, campaign.CallingController)); } return(View(campaign)); }
public static Campaign CreateCampaignFromCampaignAddView(CampaignAddView campaignAddView, IPrincipal user) { ApplicationDbContext db = new ApplicationDbContext(); Campaign newCampaign = CreateCampaignFromCampaignAddView(db, campaignAddView, user); db.Dispose(); return(newCampaign); }
// GET: Campaigns/Create public ActionResult Create() { string callingController = "Home"; string callingAction = "Index"; try { string[] callingUrlSegments = Request.UrlReferrer.Segments.Select(x => x.TrimEnd('/')).ToArray(); callingController = callingUrlSegments[callingUrlSegments.Count() - 2]; callingAction = callingUrlSegments[callingUrlSegments.Count() - 1]; } catch { } ViewBag.CallingController = callingController; CampaignAddView model = new CampaignAddView() { CallingAction = callingAction, CallingController = callingController }; return(View(model)); }
public static Campaign CreateCampaignFromCampaignAddView(ApplicationDbContext db, CampaignAddView campaignAddView, IPrincipal user) { return(CreateCampaign(db, user, campaignAddView.Name, campaignAddView.StrapLine, campaignAddView.Description, campaignAddView.Image, campaignAddView.ImageLocation, campaignAddView.Website, campaignAddView.CampaignStartDateTime, campaignAddView.CampaignEndDateTime, campaignAddView.LocationName, campaignAddView.LocationAddressLine1, campaignAddView.LocationAddressLine2, campaignAddView.LocationAddressLine3, campaignAddView.LocationAddressTownCity, campaignAddView.LocationAddressCounty, campaignAddView.LocationAddressTownCity, campaignAddView.LocationTelephoneNumber, campaignAddView.LocationEmail, campaignAddView.LocationContactName, EntityStatusEnum.Active)); }