public override ModelBase Get(Guid id) { PressRelease pressRelease = null; using (var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ClarabridgeConnectionString"].ConnectionString)) { sqlConnection.Open(); using (var sqlCommand = new SqlCommand() { CommandText = "pressRelease_Get", CommandType = CommandType.StoredProcedure, Connection = sqlConnection, Parameters = { new SqlParameter("Id", id) } }) { SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { pressRelease = new PressRelease() { Id = (Guid)sqlDataReader["Id"], Title = sqlDataReader["Title"].ToString(), DescriptionHtml = sqlDataReader["DescriptionHtml"].ToString(), DatePublished = Convert.ToDateTime(sqlDataReader["DatePublished"]), DateCreated = Convert.ToDateTime(sqlDataReader["DateCreated"]), DateUpdated = (sqlDataReader["DateUpdated"] == DBNull.Value ? new DateTime?() : Convert.ToDateTime(sqlDataReader["DateUpdated"])) }; } } } return(pressRelease); }
public async Task <IActionResult> Create(PressRelease viewModel, IFormFile file) { if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated) { return(NotFound()); } if (ModelState.IsValid) { await _pressReleaseService.AddFile(viewModel, file); var Id = await _pressReleaseService.Add(viewModel); if (!String.IsNullOrEmpty(Request.Form["continue"])) { return(RedirectToAction("Edit", new { Id = Id })); } if (!String.IsNullOrEmpty(Request.Form["new"])) { return(RedirectToAction(nameof(Create))); } return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public async Task AddFile(PressRelease viewModel, IFormFile file) { string subPath = @"wwwroot\uploaded_files"; // Your code goes here if (file != null && file.Length > 0) { DirectoryInfo di = Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), subPath)); var filePath = Path.Combine(Directory.GetCurrentDirectory(), subPath, file.FileName); // If file with same name exists delete it //if (System.IO.File.Exists(file.FileName)) //{ // System.IO.File.Delete(file.FileName); //} // Create new local file and copy contents of uploaded file //using (var localFile = System.IO.File.OpenWrite(filePath)) using (var uploadedFile = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(uploadedFile); } viewModel.MediaPath = file.FileName; } }
public void AlertServiceTest() { User user = new User { UserId = 1, EmailAddress = "*****@*****.**" }; MailingList pressReleaseList = new MailingList(); pressReleaseList.Subscribers.Add(user); PressRelease pressRelease = new PressRelease { PressReleaseId = 1, Headline = "Test Release", Body = "Press release body", IsActive = true, IsDeleted = false, MailingList = pressReleaseList }; Logger logger = new Logger(); EmailSender emailSender = new EmailSender(logger); PressReleaseAlertService pressReleaseAlertService = new PressReleaseAlertService(emailSender); pressReleaseAlertService.SendAlerts(pressRelease); }
public HttpResponseMessage Post(PressRelease pressRelease) { ResponseInfoDetail response; if (pressRelease.Id == null || pressRelease.Id == Guid.Empty) { response = new Business.PressRelease().Add(pressRelease); } else { response = new Business.PressRelease().Update(pressRelease); } if (response.Errors != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "<br/>" + String.Join("<br/>", response.Errors.Select(e => e.Message)))); } //Send SignalR Notification to all clients as Press Releases have been added/updated System.Threading.Tasks.Task.Factory.StartNew(() => this.BroadcastPressReleaseNotification()); var result = response.Item as PressRelease; return(Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("Id", result.Id), new JProperty("Title", result.Title), new JProperty("DescriptionHtml", result.DescriptionHtml), new JProperty("DatePublished", Business.Common.Formatters.DateTimeFormats.Format_DatePicker(result.DatePublished)), new JProperty("DatePublishedFormatted", Business.Common.Formatters.DateTimeFormats.FormatShortDate_WithTime(result.DatePublished)) ))); }
public ActionResult EditPressRelease(PressRelease PR) { if (PR.FileName != null && PR.FileName.ContentLength > 0) { PR.PDFExtension = Path.GetExtension(PR.FileName.FileName).Trim('.'); PR.PDFName = Path.GetFileNameWithoutExtension(PR.FileName.FileName); PR.PDFGUID = Guid.NewGuid().ToString("N"); string PdfFileLocation = Server.MapPath("~/Resources/Documents/PressRelease/" + PR.PDFGUID + "." + PR.PDFExtension); PR.FileName.SaveAs(PdfFileLocation); } DateTime SDate; DateTime.TryParseExact(PR.Date, "MM/dd/yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out SDate); PR.PressDate = SDate; string GUID = ((UserAccount)Session["UserAccount"]).GUID.ToString(); PR.SystemIp = GetRemoteIp.GetIPAddress(HttpContext); if (_aboutUsDao.SavePressRelease(PR, new Guid(GUID)) > 0) { return(RedirectToAction("ViewPublications")); } return(PartialView()); }
public void Save(PressRelease entity) { if (entity.IsDeleted) { // maybe do somethings like alert admins that a press release is being deleted. } _pressReleaseRepository.Add(entity); }
public ActionResult EditPressRelease(string EncryptedId) { if (!string.IsNullOrEmpty(EncryptedId)) { PressRelease AU = _aboutUsDao.GetbyGuidPress(!string.IsNullOrEmpty(EncryptedId) ? new Guid(EncryptedId) : Guid.Empty); return(PartialView(AU)); } return(View()); }
public void SendAlerts(PressRelease release) { foreach (var user in release.MailingList.Subscribers) { SendMessage(this, new SendMessageEventArgs { Email = user.EmailAddress, Message = "this is the message!" }); } }
public async Task <PressRelease> Add(PressRelease viewModel) { var model = _mapper.Map <PressReleaseEntity>(viewModel); _context.PressReleases.Add(model); await _context.SaveChangesAsync(); _mapper.Map(model, viewModel); return(viewModel); }
public async Task <PressRelease> Update(PressRelease viewModel) { if (viewModel.Id == null) { throw new ArgumentNullException(nameof(viewModel.Id)); } var data = await _context.PressReleases.FirstOrDefaultAsync(c => c.Id == viewModel.Id); _mapper.Map(viewModel, data); _context.Update(data); await _context.SaveChangesAsync(); return(viewModel); }
public async Task <IActionResult> Edit(int Id, PressRelease viewModel, IFormFile file) { if (Id == null) { return(NotFound()); } if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated) { return(NotFound()); } if (ModelState.IsValid) { try { await _pressReleaseService.AddFile(viewModel, file); await _pressReleaseService.Update(viewModel); if (!String.IsNullOrEmpty(Request.Form["continue"])) { return(RedirectToAction("Edit", new { Id = Id })); } if (!String.IsNullOrEmpty(Request.Form["new"])) { return(RedirectToAction(nameof(Create))); } return(RedirectToAction(nameof(Index))); } catch (DBConcurrencyException) { var exists = await Exists(viewModel.Id); if (!exists) { return(NotFound()); } else { throw; } } } return(View(viewModel)); }
public async Task <IActionResult> DeleteConfirmed(int?Id, PressRelease viewModel) { await _pressReleaseService.Remove(Id); return(RedirectToAction(nameof(Index))); }