public HttpResponseMessage Requeue(HttpRequestMessage request, QueuedEmailVM queuedEmailModel) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No items found"); if (true) { var queuedEmail = _queuedEmailService.GetQueuedEmailById(queuedEmailModel.Id); if (queuedEmail == null) { //No email found with the specified id Url.Route("QueuedEmailSearchModel", null); string nuri = Url.Link("QueuedEmailSearchModel", null); response.Headers.Location = new Uri(nuri); return response; } var requeuedEmail = new QueuedEmail { PriorityId = queuedEmail.PriorityId, From = queuedEmail.From, FromName = queuedEmail.FromName, To = queuedEmail.To, ToName = queuedEmail.ToName, ReplyTo = queuedEmail.ReplyTo, ReplyToName = queuedEmail.ReplyToName, CC = queuedEmail.CC, Bcc = queuedEmail.Bcc, Subject = queuedEmail.Subject, Body = queuedEmail.Body, AttachmentFilePath = queuedEmail.AttachmentFilePath, AttachmentFileName = queuedEmail.AttachmentFileName, AttachedDownloadId = queuedEmail.AttachedDownloadId, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = queuedEmail.EmailAccountId, DontSendBeforeDateUtc = (queuedEmailModel.SendImmediately || !queuedEmailModel.DontSendBeforeDate.HasValue) ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(queuedEmailModel.DontSendBeforeDate.Value) }; _queuedEmailService.InsertQueuedEmail(requeuedEmail); _baseService.Commit(); Url.Route("GetQueuedEmailById", new { id = requeuedEmail.Id }); string newUri = Url.Link("GetQueuedEmailById", new { id = requeuedEmail.Id }); response.Headers.Location = new Uri(newUri); return response; } else { response = request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized user"); } return response; })); }
public HttpResponseMessage EditQueuedEmail(HttpRequestMessage request, QueuedEmailVM model, bool continueEditing = false) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No items found"); if (true) { var email = _queuedEmailService.GetQueuedEmailById(model.Id); if (email == null) { //No email found with the specified id Url.Route("QueuedEmailSearchModel", null); string nuri = Url.Link("QueuedEmailSearchModel", null); response.Headers.Location = new Uri(nuri); return response; } if (ModelState.IsValid) { email = model.ToEntity(email); email.DontSendBeforeDateUtc = (model.SendImmediately || !model.DontSendBeforeDate.HasValue) ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value); _queuedEmailService.UpdateQueuedEmail(email); _baseService.Commit(); //SuccessNotification(_localizationService.GetResource("Admin.System.QueuedEmails.Updated")); if (continueEditing) { Url.Route("GetQueuedEmailById", new { id = email.Id }); string nUri = Url.Link("GetQueuedEmailById", new { id = email.Id }); response.Headers.Location = new Uri(nUri); } else { Url.Route("QueuedEmailSearchModel", null); string nuri = Url.Link("QueuedEmailSearchModel", null); response.Headers.Location = new Uri(nuri); } } else { //If we got this far, something failed, redisplay form model.PriorityName = email.Priority.GetLocalizedEnum(_localizationService, _baseService.WorkContext); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(email.CreatedOnUtc, DateTimeKind.Utc); if (email.SentOnUtc.HasValue) { model.SentOn = _dateTimeHelper.ConvertToUserTime(email.SentOnUtc.Value, DateTimeKind.Utc); } if (email.DontSendBeforeDateUtc.HasValue) { model.DontSendBeforeDate = _dateTimeHelper.ConvertToUserTime(email.DontSendBeforeDateUtc.Value, DateTimeKind.Utc); } response = request.CreateResponse <QueuedEmailVM>(HttpStatusCode.OK, model); } } else { response = request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized user"); } return response; })); }
public static QueuedEmail ToEntity(this QueuedEmailVM model, QueuedEmail destination) { return(model.MapTo(destination)); }
public static QueuedEmail ToEntity(this QueuedEmailVM model) { return(model.MapTo <QueuedEmailVM, QueuedEmail>()); }