public async Task <IActionResult> Edit(int id, [Bind("ApartmentId,Address,Photo,RoomsNumber")] Apartment apartment, IFormFile files)
        {
            if (id != apartment.ApartmentId)
            {
                return(RedirectToAction("NotFoundPage"));
            }

            if (ModelState.IsValid)
            {
                if (files != null)
                {
                    SavePhoto(apartment, files);
                }

                try
                {
                    _context.Update(apartment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ApartmentExists(apartment.ApartmentId))
                    {
                        return(RedirectToAction("NotFoundPage"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(apartment));
        }
Example #2
0
        public async Task <IActionResult> Edit(String id, [Bind("Id,FullName,Email,PhoneNumber,Address")] User user)
        {
            if (!id.Equals(user.Id))
            {
                return(RedirectToAction("NotFoundPage"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    User dbUser = (User)_context.Users.First(u => u.Id == id);
                    dbUser.PhoneNumber = user.PhoneNumber;
                    dbUser.FullName    = user.FullName;
                    dbUser.Address     = user.Address;
                    _context.Update(dbUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(RedirectToAction("NotFoundPage"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(user));
        }
Example #3
0
        public async Task <IActionResult> Edit(string id, [Bind("CompanyId,Status,Title,Content,Resources")] Company Company, IFormFile files)
        {
            if (id != Company.CompanyId)
            {
                return(RedirectToAction("NotFoundPage"));
            }

            if (ModelState.IsValid)
            {
                if (files != null)
                {
                    SavePhoto(Company, files);
                }

                if (!CompanyExists(Company.CompanyId))
                {
                    return(RedirectToAction("NotFoundPage"));
                }

                // Getting the Company from db
                var CompanyToSave = _context.Company.First(mal => mal.CompanyId == id);

                // Setting the new values
                CompanyToSave.ModifiedDate = DateTime.Now;
                CompanyToSave.Status       = Company.Status;
                CompanyToSave.Title        = Company.Title;
                CompanyToSave.Content      = Company.Content;
                CompanyToSave.Resources    = Company.Resources;

                // Updating the new Company
                _context.Update(CompanyToSave);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(Company));
        }