Ejemplo n.º 1
0
        public ContentResult Save(int?id, FormCollection actionValues)
        {
            var courtId = String.IsNullOrEmpty(actionValues["court"])
                                ? activeCourtId
                                : Convert.ToInt32(actionValues["court"]);
            var action  = new DataAction(actionValues);
            var booking = new CourtBookingModel()
            {
                Id   = Convert.ToInt64(actionValues["id"]),
                User = new UserModel()
                {
                    Id = Int32.Parse(((ClaimsIdentity)this.User.Identity).FindFirstValue("Id"))
                },
                Court = new CourtModel()
                {
                    Id = courtId
                },
                StartDate = Convert.ToDateTime(actionValues["start_date"]),
                EndDate   = Convert.ToDateTime(actionValues["end_date"])
            };

            try
            {
                switch (action.Type)
                {
                case DataActionTypes.Insert:
                    if (!IsCourt(activeCourtId) || booking.StartDate.Day < DateTime.UtcNow.Day)
                    {
                        throw new Exception("You cant book unknow court");
                    }
                    _bookingServices.Create(booking);
                    break;

                case DataActionTypes.Delete:
                    _bookingServices.Delete(booking.Id);
                    break;

                default:
                    if (booking.StartDate.Day < DateTime.UtcNow.Day)
                    {
                        throw new Exception("This day is unvalid!");
                    }
                    _bookingServices.Update(booking.Id, booking);
                    break;
                }
                action.TargetId = Convert.ToInt64(actionValues["id"]);
            }
            catch
            {
                action.Type = DataActionTypes.Error;
            }
            return(new AjaxSaveResponse(action));
        }
Ejemplo n.º 2
0
 public ActionResult DeclineBookingCourt(int id, CourtBookingModel model)
 {
     try
     {
         _bookingServices.Delete(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 3
0
 public void Update(long id, CourtBookingModel model)
 {
     _bookingRepository.Update(id, model.StartDate, model.EndDate);
 }
Ejemplo n.º 4
0
 public void Create(CourtBookingModel model)
 {
     _bookingRepository.Add(model.StartDate, model.EndDate, model.Court.Id, model.User.Id);
 }