Example #1
0
        public async Task <ActionResult> Create(ApartmentBooking model)
        {
            //if (ModelState.IsValid)
            {
                var errorsResult = ApartmentBookingValidationContext.Validate(model);
                if (errorsResult.Any())
                {
                    ModelState.Clear();

                    foreach (var error in errorsResult)
                    {
                        ModelState.AddModelError(error.Key, error.Value);
                    }
                    TempData["ValidationErrors"] = true;

                    return(View(model));
                }
                else
                {
                    db.ApartmentBookings.Add(model);
                    await db.SaveChangesAsync();
                }

                return(RedirectToAction("Index"));
            }

            //return View(model);
        }
Example #2
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            ApartmentBooking mydata = await db.ApartmentBookings.FindAsync(id);

            db.ApartmentBookings.Remove(mydata);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #3
0
        // GET: /Home/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ApartmentBooking model = await db.ApartmentBookings.FindAsync(id);

            if (model == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
        public void DateFromIsNotGreaterThanNow()
        {
            ApartmentBooking model = new ApartmentBooking()
            {
                DateFrom = DateTime.Now.AddDays(-1)
            };

            var errorsResult = ApartmentBookingValidationContext.Validate(model);

            if (errorsResult.Any())
            {
                foreach (var error in errorsResult)
                {
                    //error.Key, error.Value
                }
            }
            else
            {
                //ok
            }

            Assert.True(errorsResult.First().Key == "DateFrom");
        }