Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("IdHome,IdAdverts,IdUser,IdApartament,TownDistrict,Adress,NumOfRooms,Square,AboutHome,Price,Image")] AllAdverts allAdverts)
        {
            if (id != allAdverts.IdHome)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(allAdverts);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AllAdvertsExists(allAdverts.IdHome))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdAdverts"]    = new SelectList(_context.TypeOfAdvert, "IdAdvert", "IdAdvert", allAdverts.IdAdverts);
            ViewData["IdApartament"] = new SelectList(_context.TypeOfApartament, "IdApartament", "TypeOfApartament1", allAdverts.IdApartament);
            ViewData["IdUser"]       = new SelectList(_context.AspNetUsers, "Id", "Id", allAdverts.IdUser);
            return(View(allAdverts));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("IdHome,IdAdverts,IdUser,IdApartament,TownDistrict,Adress,NumOfRooms,Square,AboutHome,Price,Image")] AllAdverts allAdverts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(allAdverts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdAdverts"]    = new SelectList(_context.TypeOfAdvert, "IdAdvert", "IdAdvert", allAdverts.IdAdverts);
            ViewData["IdApartament"] = new SelectList(_context.TypeOfApartament, "IdApartament", "TypeOfApartament1", allAdverts.IdApartament);
            ViewData["IdUser"]       = new SelectList(_context.AspNetUsers, "Id", "Id", allAdverts.IdUser);
            return(View(allAdverts));
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateAdvert(RegisterAdvertViewModel advertModel)
        {
            AdvertViewModel advertViewModel = new AdvertViewModel();

            advertViewModel.allAdverts = _repositoryWrapper.Advert.findAll();
            int advertsCount = advertViewModel.allAdverts.Count() + 1;

            if (ModelState.IsValid)
            {
                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(advertModel.Image.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)advertModel.Image.Length);
                }
                AllAdverts advert = new AllAdverts
                {
                    IdHome       = advertsCount + 1,
                    IdAdverts    = advertModel.IdSelectedAdvert,
                    IdUser       = userId,
                    IdApartament = advertModel.IdSelectedApartament,
                    TownDistrict = advertModel.TownDistrict,
                    Adress       = advertModel.Adress,
                    NumOfRooms   = advertModel.NumOfRooms,
                    Square       = advertModel.Square,
                    AboutHome    = advertModel.AboutHome,
                    Price        = advertModel.Price,
                    Image        = imageData
                };
                if (advert != null)
                {
                    _context.AllAdverts.Add(advert);
                    _context.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }