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)); }
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(); }