예제 #1
0
        //[Authorize(Roles ="ADMIN, DIRECTOR, SUPERVISOR")]
        public async Task <IActionResult> PutCuriosityLike(int curiosityId, int numberOfLikes)
        {
            var curiosityLike = await _context.CuriosityLikes.FirstOrDefaultAsync(l => l.CuriosityId == curiosityId);

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

            curiosityLike.Likes = numberOfLikes;

            _context.Entry(curiosityLike).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CuriosityLikeExists(curiosityLike.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutComment(int id, [FromForm] Comment comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> PutTour(int id, [FromForm] TourPutDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tour = await _context.Tours.FindAsync(id);

            if (tour == null)
            {
                ModelState.AddModelError("", $"Tour with id : {id} not found");
                return(NotFound(ModelState));
            }

            if (model.Image != null)
            {
                if (tour.Image != null)
                {
                    //string filePath = Path.Combine(webHostEnvironment.WebRootPath,
                    //    "TourImages", tour.Image);
                    //System.IO.File.Delete(filePath);

                    await _AzureFileService.DeleteTourImageAsync(tour.Image);
                }

                //tour.Image = ProcessUploadedFile(model);
                tour.Image = await _AzureFileService.ProcessTourImgAsync(model);
            }

            tour.City        = model.City;
            tour.Coordinates = model.Coordinates;
            tour.Country     = model.Country;
            tour.Description = model.Description;
            tour.Latitude    = model.Latitude;
            tour.Longitude   = model.Longitude;
            tour.Name        = model.Name;
            tour.Province    = model.Province;
            tour.Region      = model.Region;
            tour.Type        = model.Type;

            _context.Entry(tour).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TourExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> PutCuriosity(int id, [FromForm] CuriositiesPutDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }


            var curiosity = await _context.Curiosities.FindAsync(id);

            if (curiosity == null)
            {
                ModelState.AddModelError("", $"Curiosity with id : ${id} not found");
                return(NotFound(ModelState));
            }

            string uniqueFileName = "";

            if (model.Image != null)
            {
                if (curiosity.Image != null)
                {
                    await _AzureFileService.DeleteCuriosityImageAsync(curiosity.Image);

                    //string filePath = Path.Combine(webHostEnvironment.WebRootPath,
                    //    "images", curiosity.Image);
                    //System.IO.File.Delete(filePath);
                }

                //if (model.ExistingImage != null)
                //{
                //    string filePath = Path.Combine(webHostEnvironment.WebRootPath,
                //        "images", model.ExistingImage);
                //    System.IO.File.Delete(filePath);
                //}
                //curiosity.Image = ProcessUploadedFile(model);
                uniqueFileName = await _AzureFileService.ProcessFotoAsync(model);

                curiosity.Image = uniqueFileName;
            }
            curiosity.City        = model.City;
            curiosity.Coordinates = model.Coordinates;
            curiosity.Country     = model.Country;
            curiosity.Description = model.Description;
            curiosity.Latitude    = model.Latitude;
            curiosity.Longitude   = model.Longitude;
            curiosity.Name        = model.Name;
            curiosity.Period      = model.Period;
            curiosity.Province    = model.Province;
            curiosity.Region      = model.Region;
            curiosity.Type        = model.Type;

            //_context.Update(curiosity);


            _context.Entry(curiosity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CuriosityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }