Esempio n. 1
0
        public async Task <IActionResult> Create(DateTime date)
        {
            ViewBag.anotherDate = "סמן תאריך נוסף כתפוס";
            if (ModelState.IsValid)
            {
                ApartmentAvailability apartmentAvailability = new ApartmentAvailability();
                apartmentAvailability.Apartment = _context.Apartment.Where(u => u.Id == (int)TempData["Availability"]).FirstOrDefault();
                var result = from a in _context.ApartmentAvailability
                             where (a.Apartment.Equals(apartmentAvailability.Apartment)) && (a.Availability.NotAvailable.Equals(date))
                             select a;

                if (result.ToList().Count() > 0)
                {
                    ViewBag.errorTime = "*התאריך שבחרת כבר סומן כתפוס";
                }
                else if (date.CompareTo(DateTime.Now.AddMonths(3)) > 0)
                {
                    ViewBag.errorTime = "*יש להזין תאריכים בתווך של 3 חודשים מהיום";
                }
                else
                {
                    ViewBag.errorTime = "*התאריך הוזן במערכת, ניתן לסמן תאריך נוסף";
                    apartmentAvailability.Availability   = _context.Availability.Where(a => a.NotAvailable.Equals(date)).FirstOrDefault();;
                    apartmentAvailability.AvailabilityId = apartmentAvailability.Availability.Id;
                    apartmentAvailability.ApartmentId    = (int)TempData["Availability"];
                    _context.Add(apartmentAvailability);
                    await _context.SaveChangesAsync();
                }

                TempData["Availability"] = TempData["Availability"];
            }

            //ViewData["AvailabilityId"] = new SelectList(_context.Availability, "Id", "Id", apartmentAvailability.AvailabilityId);
            return(View());
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ApartmentId,AvailabilityId")] ApartmentAvailability apartmentAvailability)
        {
            if (id != apartmentAvailability.AvailabilityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(apartmentAvailability);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ApartmentAvailabilityExists(apartmentAvailability.AvailabilityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApartmentId"]    = new SelectList(_context.Apartment, "Id", "Id", apartmentAvailability.ApartmentId);
            ViewData["AvailabilityId"] = new SelectList(_context.Availability, "Id", "Id", apartmentAvailability.AvailabilityId);
            return(View(apartmentAvailability));
        }