コード例 #1
0
        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;
        }
コード例 #2
0
        //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;
        }
コード例 #3
0
 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();
     }
 }