public void Save(ProgramViewSD model) { try { if (model.ImageFile != null && model.ImageFile.ContentLength > 0) { var fileName = DataAccess.Utilities.GenerateUniqueID() + Path.GetExtension(model.ImageFile.FileName); try { var result = AwsHelpers.UploadImage(fileName, model.ImageFile); model.Program.Image = fileName; } catch (Exception ex) { string s = string.Empty; } } } catch (Exception ex) { string s = string.Empty; } using (var projectProvider = new ProgramProvider()) { if (model.New) { try { projectProvider.Insert(model.Program); } catch (Exception ex) { if (ex.Message.ContainsValue("PRIMARY")) { projectProvider.Update(model.Program); } } } else { projectProvider.Update(model.Program); } } }
public ActionResult Create(ProgramViewSD item) { if (ModelState.IsValid) { if (item.ImageFile != null && item.ImageFile.ContentLength > 0) { var fileName = DataAccess.Utilities.GenerateUniqueID() + Path.GetExtension(item.ImageFile.FileName); try { var result = AwsHelpers.UploadImage(fileName, item.ImageFile); item.Program.Image = fileName; } catch (Exception ex) { AlertMessage = "Your program has been saved successfully, but there was a problem uploading your image. Please contact our support if you continue to have problems."; } } using (var provider = new ProgramProvider()) { if (string.IsNullOrEmpty(item.Program.StartDate)) { item.Program.StartDate = DateTime.Now.ToShortDateString(); } if (string.IsNullOrEmpty(item.Program.EventStartTime)) { item.Program.EventStartTime = "12:00 AM"; } if (string.IsNullOrEmpty(item.Program.EventStopTime)) { item.Program.EventStopTime = "12:00 AM"; } provider.Insert(item.Program); } return Redirect("/Site/ViewProgram/" + item.Program.Id); } return View(DefaultViews.CreateEdit, item); }