Exemplo n.º 1
0
        public async Task <IActionResult> EditAd(EditAdInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            await adService.EditAd(model.Id, model.Title, model.Description, model.PropertyType, model.Size,
                                   model.Location, model.RentPrice, model.BuildingClass);

            var currentUserProfile = this.User.Identity.Name;
            var ads          = this.adService.GetAgencyAds(currentUserProfile);
            var minimizedAds = AdToAdViewModel(ads);

            return(this.View("MyAds", minimizedAds));
        }
Exemplo n.º 2
0
        public IActionResult EditAd(int id)
        {
            var ad = adService.GetAd(id);

            var model = new EditAdInputModel
            {
                Id            = ad.Id,
                Title         = ad.Title,
                Description   = ad.Description,
                RentPrice     = ad.RentPrice,
                BuildingClass = ad.BuildingClass.ToString(),
                Location      = ad.Location,
                PropertyType  = ad.PropertyType.ToString(),
                Size          = ad.Size,
            };

            return(this.View(model));
        }
Exemplo n.º 3
0
        public async Task EditAd(EditAdInputModel inputModel)
        {
            var adFromDb = await context.Ads.FirstOrDefaultAsync(x => x.Id == inputModel.AdId);

            if (adFromDb == null)
            {
                throw new ArgumentException(GlobalConstants.InvalidAdIdErrorMessage);
            }

            var imageUrls = inputModel.EditAdDetailsInputModel.Images
                            .Select(async x =>
                                    await cloudinaryService.UploadPictureAsync(x, inputModel.EditAdDetailsInputModel.Title))
                            .Select(x => x.Result)
                            .ToList();

            adFromDb.Title             = inputModel.EditAdDetailsInputModel.Title;
            adFromDb.Description       = inputModel.EditAdDetailsInputModel.Description;
            adFromDb.Price             = inputModel.EditAdDetailsInputModel.Price;
            adFromDb.AvailabilityCount = inputModel.EditAdDetailsInputModel.Availability;
            adFromDb.ConditionId       = inputModel.EditAdDetailsInputModel.ConditionId;

            foreach (var image in imageUrls)
            {
                adFromDb.Images.Add(new Image {
                    ImageUrl = image
                });
            }

            adFromDb.Address.Country      = inputModel.EditAdAddressInputModel.Country;
            adFromDb.Address.City         = inputModel.EditAdAddressInputModel.City;
            adFromDb.Address.Street       = inputModel.EditAdAddressInputModel.Street;
            adFromDb.Address.District     = inputModel.EditAdAddressInputModel.District;
            adFromDb.Address.ZipCode      = inputModel.EditAdAddressInputModel.ZipCode;
            adFromDb.Address.PhoneNumber  = inputModel.EditAdAddressInputModel.PhoneNumber;
            adFromDb.Address.EmailAddress = inputModel.EditAdAddressInputModel.EmailAddress;

            context.Ads.Update(adFromDb);
            await context.SaveChangesAsync();
        }