Beispiel #1
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));
        }
        public async Task <IActionResult> Create([Bind("ApartmentId,Address,Photo,RoomsNumber")] Apartment apartment, IFormFile files)
        {
            if (ModelState.IsValid)
            {
                // Getting the long lat
                var location = AddLongLatAsync(apartment.Address);
                apartment.Latitude  = location.Result.Latitude;
                apartment.Longitude = location.Result.Longitude;
                SavePhoto(apartment, files);
                _context.Add(apartment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(apartment));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("CurrentApartment")] int CurrentApartment, [Bind("RequestedBy")] string RequestedBy, [Bind("MalfunctionId,Status,Title,Content,Resources,CurrentApartmentId,RequestedById")] Malfunction malfunction, IFormFile mFiles)
        {
            if (ModelState.IsValid)
            {
                // Creating the query of the apartment
                var queryApt = from apt in _context.Apartment
                               where apt.ApartmentId == CurrentApartment
                               select apt;

                // Creating the query of the user
                var queryUsr = from usr in _context.User
                               where usr.Id == RequestedBy
                               select usr;

                // If the id of the apartment/user does not exist in DB
                if (!queryApt.Any() || !queryApt.Any())
                {
                    return(View(malfunction));
                }

                // Adding the apartment to the malfunction to save
                var curApartment = queryApt.First();
                malfunction.CurrentApartment = curApartment;

                // Adding the user to the malfunction to save
                var curUser = queryUsr.First();
                malfunction.RequestedBy = curUser;

                // Adding the creation date and modification date
                malfunction.CreationDate = DateTime.Now;
                malfunction.ModifiedDate = DateTime.Now;

                // Uploading photo describing the malfunction
                SavePhoto(malfunction, mFiles);

                _context.Add(malfunction);
                await _context.SaveChangesAsync();

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