public HttpResponseMessage PostPhotoEmail(PhotoEmail photoEmail) { if (!ModelState.IsValid || photoEmail == null) { throw new HttpResponseException(Request.CreateResponse <IEnumerable <ModelError> >(HttpStatusCode.BadRequest, this.ModelState.Values.SelectMany(v => v.Errors))); } this.db.PhotoEmails.Add(photoEmail); try { this.db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { FotoShoutUtils.Log.LogManager.Error(PhotoEmailsController._logger, (object)((object)ex).ToString()); throw new HttpResponseException(Request.CreateResponse <string>(HttpStatusCode.NotFound, ex.Message)); } HttpResponseMessage response = Request.CreateResponse <PhotoEmail>(HttpStatusCode.Created, photoEmail); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "PhotoEmails", id = photoEmail.PhotoId })); return(response); }
public HttpResponseMessage PutPhotoEmail(int photoEmailId, PhotoEmail photoEmail) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.Values.SelectMany(v => v.Errors))); } if (photoEmailId != photoEmail.PhotoEmailId) { FotoShoutUtils.Log.LogManager.Error(PhotoEmailsController._logger, (object)string.Format("Ids need to be identical when updating the email status {0} of the photo {1}.", photoEmailId, photoEmail.PhotoId)); throw new HttpResponseException(Request.CreateResponse <string>(HttpStatusCode.BadRequest, string.Format("Ids need to be identical when updating the email status {0} of the photo {1}.", photoEmailId, photoEmail.PhotoId))); } db.Entry(photoEmail).State = EntityState.Modified; try { this.db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { FotoShoutUtils.Log.LogManager.Error(PhotoEmailsController._logger, ex.ToString()); throw new HttpResponseException(Request.CreateResponse <string>(HttpStatusCode.NotFound, ex.Message)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
private void SendEmails(UserTDO user, EventTDO ev, PhotoTDO photo, PhotoAnnotation photoAnnotation, string photoUrl) { if (ev.WebsiteId != null) { Website website = _fsWebService.Get <Website>("Websites/" + ev.WebsiteId, true); photoUrl = GeneratePhotoWebsiteUrl(photoUrl, website); // string.Format("{0}PhotoWebsite/{1}?website={2}", Regex.Replace(AppSettings.FsApiBaseAddress, @"api/", ""), photo.PhotoId, ev.WebsiteId); } ICollection <GuestTDO> guests = photoAnnotation.Guests; IEnumerable <PhotoEmail> list = this._fsWebService.GetList <PhotoEmail>("PhotoEmails/" + (object)photo.PhotoId, true); foreach (GuestTDO guestTdo in (IEnumerable <GuestTDO>)guests) { GuestTDO guest = guestTdo; bool flag = true; PhotoEmail postObject = list.Where(ee => ee.PhotoId == photo.PhotoId && ee.GuestId == guest.GuestId).FirstOrDefault(); if (postObject == null) { postObject = new PhotoEmail { EventId = ev.EventId, PhotoId = photo.PhotoId, GuestId = guest.GuestId }; flag = false; } else if (postObject.Status == (byte)1) { continue; } this._emailService.Error = ""; this._emailService.SendEmailTo(user, ev, guest, photoUrl); if (string.IsNullOrEmpty(this._emailService.Error)) { postObject.Status = (byte)1; postObject.Error = null; } else { postObject.Status = byte.MaxValue; postObject.Error = this._emailService.Error; } if (flag) { this._fsWebService.UploadString("PhotoEmails?photoEmailId=" + (object)postObject.PhotoEmailId, this.GeneratePostContent <PhotoEmail>(postObject), "PUT"); } else { this._fsWebService.UploadString("PhotoEmails", this.GeneratePostContent <PhotoEmail>(postObject), null); } } }