コード例 #1
0
        public async Task <HttpResponseMessage> UploadPhoto(string title, string description = "")
        {
            var model = new PhotoLoadDTO()
            {
                Title       = title,
                Description = description,
                Binary      = await Request.Content.ReadAsByteArrayAsync(),
                UserId      = User.Identity.GetUserId()
            };

            if (model.Binary == null || string.IsNullOrEmpty(model.Title))
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            Service.Save(model);
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
コード例 #2
0
        public void Save(PhotoLoadDTO inputPhoto)
        {
            var photo = new Photo()
            {
                Name          = inputPhoto.Title,
                Description   = inputPhoto.Description,
                UploadDate    = DateTime.Now,
                Raiting       = 0,
                AmountOfVoted = 0,
                PhotoBytes    = new BinaryPhoto()
                {
                    Picture = inputPhoto.Binary
                },
                UserId = inputPhoto.UserId,
            };

            context.Photos.Add(photo);
            context.SaveChanges();
        }