public HttpResponseMessage PostPicture(PictureModel model) { HttpResponseMessage response = new HttpResponseMessage(); var identity = (ClaimsIdentity)User.Identity; var user = _db.Users.Where(u => u.AuthUserId.Equals(identity.GetUserId())).First(); var subscriptions = _db.Subscriptions.Where(s => s.UserId == user.Id); var allowUpload = false; foreach (Subscription s in subscriptions) { if (s.VacationId == model.VacId) { allowUpload = true; } } if (allowUpload) { _db.Pictures.Add(new PictureMTEAdapter().MapData(model)); _db.SaveChanges(); response.StatusCode = HttpStatusCode.OK; } else { response.StatusCode = HttpStatusCode.Unauthorized; } return response; }
//private VacationMTEAdapter vacationAdapter = new VacationMTEAdapter(); public Picture MapData(PictureModel pictureModel) { Picture pic = new Picture(); if (pictureModel != null) { pic.Id = pictureModel.Id; pic.Titel = pictureModel.Titel; pic.Url = pictureModel.Url; pic.Description = pictureModel.Description; pic.VacationId = pictureModel.VacId; } return pic; }
public PictureModel MapData(Picture p) { if (p != null) { PictureModel pm = new PictureModel(); pm.Id = p.Id; pm.Titel = p.Titel; pm.Description = p.Description; pm.Url = p.Url; pm.VacId = p.VacationId; return pm; } else { return new PictureModel(); } }