public async Task <ActionResult> PutService(int id, [FromBody] GalleryUM gallery) { Gallery galleryUpdated = await _service.GetByIdAsync(id); if (galleryUpdated == null || id != gallery.Id) { return(BadRequest()); } /*int accountId = 3; * int serviceTypeId = 1; * int galleryId = 1;*/ try { galleryUpdated.Id = gallery.Id; galleryUpdated.Name = gallery.Name; galleryUpdated.Description = gallery.Description; /*galleryUpdated.DefaultImageId = gallery.DefaultImageId;*/ /*serviceUpdated.Price = service.Price; * serviceUpdated.EstimateTime = service.EstimateTime; * serviceUpdated.Status = service.Status; * serviceUpdated.UpdatedDate = DateTime.Now; * serviceUpdated.AccountId = accountId; * serviceUpdated.ServiceTypeId = serviceTypeId; * serviceUpdated.GalleryId = galleryId;*/ _service.Update(galleryUpdated); await _service.Save(); } catch (Exception e) { return(BadRequest(e)); } return(NoContent()); }
public ActionResult <IEnumerable <ImageVM> > GetAllGallery([FromQuery] ImageSM model, int pageSize, int pageIndex) { IQueryable <Image> imageList = _service.GetAll(s => s.Gallery); if (!string.IsNullOrEmpty(model.ImageUrl)) { imageList = imageList.Where(s => s.ImageUrl.Contains(model.ImageUrl)); } if (!string.IsNullOrEmpty(model.Description)) { imageList = imageList.Where(s => s.Description.Contains(model.Description)); } if (model.GalleryId != 0) { // Check whether GalleryId exists, return Bad Request if does not exist if (_galleryService.GetByIdAsync(model.GalleryId) != null) { imageList = imageList.Where(s => s.GalleryId == model.GalleryId); } else { return(BadRequest()); } } if (pageSize == 0) { pageSize = 20; } if (pageIndex == 0) { pageIndex = 1; } var pagedModel = _pagingSupport.From(imageList) .GetRange(pageIndex, pageSize, s => s.Id) .Paginate <ImageVM>(); return(Ok(pagedModel)); }