public async Task <Category> Post([FromBody] Category value)
        {
            var newEntity = _context.Categories.Add(value);
            await _context.SaveChangesAsync(true);

            return(newEntity.Entity);
        }
        public async Task <IActionResult> Put(int key, [FromBody] Album album)
        {
            String userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            var entry = await _context.Albums.FindAsync(key);

            if (entry == null)
            {
                return(NotFound());
            }

            if (String.CompareOrdinal(entry.CreatedBy, userId) != 0)
            {
                return(StatusCode(401));
            }

            entry.Desp     = album.Desp;
            entry.IsPublic = album.IsPublic;
            entry.Title    = album.Title;
            _context.Entry(entry).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Updated(album));
        }
        public async Task <ActionResult> Create([Bind(Include = "Decription")] Photo photo, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid && upload != null)
            {
                string fileName = System.IO.Path.GetFileName(upload.FileName);



                using (var img = System.Drawing.Image.FromStream(upload.InputStream))
                {
                    photo.ThumbPath = String.Format("../Gallery/GalleryThumb/" + fileName);
                    photo.ImagePath = String.Format("../Gallery/GalleryImage/" + fileName);

                    // Save thumbnail size image, 100 x 100
                    SaveToFolder(img, new Size(300, 300), photo.ThumbPath);

                    // Save large size image, 800 x 800
                    SaveToFolder(img, new Size(800, 800), photo.ImagePath);
                }

                photo.CreatedOn = DateTime.Now;
                db.Photos.Add(photo);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
Beispiel #4
0
        public async Task <IActionResult> Post([FromBody] UserDetail usrdtl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid model state"));
            }

            var userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            _context.UserDetails.Add(usrdtl);
            await _context.SaveChangesAsync();

            return(Created(usrdtl));
        }
Beispiel #5
0
        private async Task HandleRequestAsync(FlickrRoot responseBody, HttpResponseMessage response)
        {
            var newPhotos = new List <string>();
            var dbPhotos  = await GetPhotosFromCache();

            foreach (var photo in responseBody.Photos.Photo)
            {
                if (dbPhotos.Find(el => el.Id == photo.Id) == null)
                {
                    newPhotos.Add(CreatePhotoUrl(photo));
                    await _context.AddAsync(photo);
                }
            }

            await _faceService.AnalyzePhotos(newPhotos);

            await _context.SaveChangesAsync();

            _memoryCache.Remove("FlickrPhotos");
        }
        private async Task <IActionResult> PhotoRequest(string url)
        {
            var response = await _http.PostAsync(_faceUrl, BuildRequest(url));

            var responseBody = JsonConvert.DeserializeObject <FacedRoot>(await response.Content.ReadAsStringAsync());
            await _galleryService.AddItem(responseBody.Faces, url);

            await _context.SaveChangesAsync();

            return(new OkResult());
        }
Beispiel #7
0
        public async Task <bool> TryCreateAsync(Genre genreForCreate)
        {
            bool success = true;

            var genreEntityExist = await _context.Genres
                                   .AnyAsync(genreEntity => genreEntity.Name == genreForCreate.Name);

            if (genreEntityExist == true)
            {
                success = false;
            }
            else
            {
                var entityGenre = _mapper.Map <GenreEntity>(genreForCreate);
                _context.Genres.Add(entityGenre);
                await _context.SaveChangesAsync();
            }

            return(success);
        }
Beispiel #8
0
        public async Task <bool> TryDeleteAsync(int id)
        {
            bool success = true;

            var photoEntityExist = await _context.Photos
                                   .FirstOrDefaultAsync(photoEntity => photoEntity.Id == id);

            if (photoEntityExist == null)
            {
                success = false;
            }
            else
            {
                var entityForDelete = _mapper.Map <PhotoEntity>(photoEntityExist);
                _context.Photos.Remove(entityForDelete);
                await _context.SaveChangesAsync();
            }

            return(success);
        }
        public async Task <bool> TryCreateAsync(User userForCreate)
        {
            bool success = true;

            var userEntityExist = await _context.Users
                                  .AnyAsync(userEntity => userEntity.Login == userForCreate.Login);

            if (userEntityExist == true)
            {
                success = false;
            }
            else
            {
                var entityUser = _mapper.Map <UserEntity>(userForCreate);
                _context.Users.Add(entityUser);
                await _context.SaveChangesAsync();
            }

            return(success);
        }
Beispiel #10
0
        public async Task <IActionResult> Post([FromBody] AddImageModel addImageModel)
        {
            //string fileName = $"{Guid.NewGuid()}.jpg";

            var filePath = $@"{_hostEnvironment}\images\{addImageModel.FileName}";

            await System.IO.File.WriteAllBytesAsync(filePath, addImageModel.Bytes);

            var image = new Image
            {
                Id       = Guid.NewGuid(),
                Title    = addImageModel.Title,
                FileName = addImageModel.FileName,
                OwnerId  = string.Empty // To use auth provider to retrieve value
            };

            _context.Images.Add(image);
            await _context.SaveChangesAsync();

            var imageModel = CreateImageModel(image);

            return(CreatedAtAction(nameof(Get), new { id = imageModel.Id }, imageModel));
        }
        public async Task <IActionResult> Put(string key, [FromBody] Photo pto)
        {
            var entry = await _context.Photos.FindAsync(key);

            if (entry == null)
            {
                return(NotFound());
            }

            string userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            entry.Desp     = pto.Desp;
            entry.IsPublic = pto.IsPublic;
            entry.Title    = pto.Title;
            _context.Entry(entry).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Updated(pto));
        }
        public async Task <IActionResult> AddItem(List <FaceFound> faces, string imageUrl)
        {
            var newfaces = FindEmotions(faces);
            var newPhoto = new GalleryPhoto
            {
                PhotoUrl    = imageUrl,
                FacesFound  = newfaces,
                TimeCreated = DateTime.Now
            };
            await _context.GalleryPhotos.AddAsync(newPhoto);

            await _context.SaveChangesAsync();

            _memoryCache.Remove("GalleryPhotos");
            return(new OkResult());
        }
Beispiel #13
0
        public void EnsureCreated()
        {
            _context.Database.EnsureCreated();
            var albums = _galleryDataService.GetAlbumsAsync().Result;

            _context.Set <Album>().AddRange(albums);

            _context.Set <User>().AddRange(albums
                                           .Select(x => x.UserId)
                                           .Distinct()
                                           .Select(x => new User
            {
                Id = x
            }));

            var photos = _galleryDataService.GetPhotosAsync().Result;

            _context.Set <Photo>().AddRange(photos);
            _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Delete([FromODataUri] string keyPhotoID, [FromODataUri] string keyTagString)
        {
            string userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            var entity = this._context.PhotoTags.Find(keyPhotoID, keyTagString);

            if (entity == null)
            {
                return(NotFound());
            }

            this._context.PhotoTags.Remove(entity);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> Post([FromBody] AlbumPhoto albpto)
        {
            var entry = await _context.AlbumPhotos.FindAsync(albpto.AlbumID, albpto.PhotoID);

            if (entry != null)
            {
                return(BadRequest());
            }

            string userId = ControllerUtility.GetUserID(this._httpContextAccessor);

            if (userId == null)
            {
                return(StatusCode(401));
            }

            _context.AlbumPhotos.Add(albpto);
            await _context.SaveChangesAsync();

            return(Created(albpto));
        }
 public virtual async Task CommitAsync()
 {
     await _context.SaveChangesAsync();
 }
Beispiel #17
0
 public async Task SaveAsync()
 {
     await galleryContext.SaveChangesAsync();
 }
        public async Task <bool> SaveAsync()
        {
            var result = await _context.SaveChangesAsync();

            return(result >= 0);
        }
Beispiel #19
0
 public async Task CommitAsync()
 {
     await db.SaveChangesAsync();
 }