コード例 #1
0
        public async Task <IActionResult> Add(PlaceInfoViewModel newPlace)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await userManager.GetUserAsync(HttpContext.User);

                var placeId = await placeService.AddPlaceAsync(newPlace, currentUser);

                if (newPlace.File != null)
                {
                    var errors = imageService.Validate(newPlace.File, newPlace);
                    if (errors.Count != 0)
                    {
                        return(View(newPlace));
                    }
                    await imageService.UploadAsync(newPlace.File, placeId.ToString(), "place");

                    await placeService.SetIndexImageAsync(placeId, "place");
                }

                return(RedirectToAction(nameof(PlaceController.MyPlace), "Place"));
            }

            return(View(newPlace));
        }
コード例 #2
0
        public async Task EditPlaceAsync(long placeId, PlaceInfoViewModel editPlace)
        {
            var placeEdit = await FindPlaceByIdAsync(placeId);

            if (placeEdit != null)
            {
                placeEdit.Price       = editPlace.Price;
                placeEdit.City        = editPlace.City;
                placeEdit.Description = editPlace.Description;
                placeEdit.PlaceUri    = editPlace.PlaceUri;
                placeEdit.PetType     = editPlace.PetType;
                applicationContext.Places.Update(placeEdit);
                await applicationContext.SaveChangesAsync();
            }
        }
コード例 #3
0
        public async Task <long> AddPlaceAsync(PlaceInfoViewModel newPlace, User user)
        {
            var city        = newPlace.City;
            var description = newPlace.Description;
            var price       = newPlace.Price;
            var petType     = newPlace.PetType;

            var place = await applicationContext.Places.AddAsync(new Place { City = city, Price = price, Description = description, PetType = petType, PlaceUri = null, UserId = user.Id });

            await applicationContext.SaveChangesAsync();

            user.PlaceId = place.Entity.PlaceId;
            await applicationContext.SaveChangesAsync();

            return(user.PlaceId);
        }
コード例 #4
0
        public async Task <IActionResult> Edit(PlaceInfoViewModel editPlace, long placeId)
        {
            if (ModelState.IsValid)
            {
                if (editPlace.File != null)
                {
                    var errors = imageService.Validate(editPlace.File, editPlace);
                    if (errors.Count != 0)
                    {
                        return(View(editPlace));
                    }
                    await placeService.EditPlaceAsync(placeId, editPlace);

                    await imageService.UploadAsync(editPlace.File, placeId.ToString(), "place");

                    await placeService.SetIndexImageAsync(placeId, "place");
                }
                return(RedirectToAction(nameof(PlaceController.MyPlace), "Place"));
            }

            return(View(editPlace));
        }
コード例 #5
0
        public List <string> Validate(IFormFile file, PlaceInfoViewModel newPlace)
        {
            if (CheckImageExtension(file))
            {
                if (file.Length < fourMegaByte)
                {
                    return(newPlace.ErrorMessages);
                }
                else
                {
                    newPlace.ErrorMessages.Add("The image max 4 MB");
                    return(newPlace.ErrorMessages);
                }
            }
            else
            {
                newPlace.ErrorMessages.Add("Please add only image formats!");
                return(newPlace.ErrorMessages);
            }

            return(newPlace.ErrorMessages);
        }