Example #1
0
        public async Task <IActionResult> Create([Bind("CurrentApartment")] int CurrentApartment, [Bind("CompanyId,Status,Title,Content,Resources,CurrentApartmentId")] Company Company, IFormFile mFiles)
        {
            if (ModelState.IsValid)
            {
                // Creating the query of the apartment
                var queryApt = from apt in _context.Apartment
                               where apt.ApartmentId == CurrentApartment
                               select apt;

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

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

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

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

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(Company));
        }
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));
        }
        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));
        }