public JsonResult PostOtherServices(CheckIn obj)
        {
            try
            {
                var ios = from io in db.InOuts
                          where io.RoomId == obj.RoomId && io.Status == 0
                          select io;
                if (ios != null && ios.Count() > 0)
                {
                    foreach (var checkout in ios)
                    {
                        if (obj.OtherServices != null)
                        {
                            foreach (var item in obj.OtherServices)
                            {
                                checkout.OtherServiceAmount = obj.OtherServiceAmount;

                                var oldService = checkout.InOut_OtherServices.SingleOrDefault(s => s.OtherServiceId == item.OtherServiceId);
                                if (oldService != null)
                                {
                                    if (item.IsDel == true)
                                    {
                                        db.InOut_OtherServices.Remove(oldService);
                                    }
                                    else
                                    {
                                        oldService.Quantity = item.Quantity;
                                    }
                                }
                                else
                                {
                                    if (item.IsDel != true)
                                    {
                                        InOut_OtherServices newService = new InOut_OtherServices();
                                        newService.InOutId        = checkout.InOutId;
                                        newService.OtherServiceId = item.OtherServiceId;
                                        newService.Quantity       = item.Quantity;
                                        db.InOut_OtherServices.Add(newService);
                                    }
                                }
                            }
                        }
                    }
                    db.SaveChanges();
                }
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, ErrInfo = ex }, JsonRequestBehavior.DenyGet));
            }
        }
 public JsonResult CheckIn(CheckIn obj)
 {
     try
     {
         InOut newCheckIn = new InOut();
         newCheckIn.RoomId             = obj.RoomId;
         newCheckIn.CheckinTime        = obj.CheckinTime;
         newCheckIn.CheckOutTime       = obj.CheckinTime;
         newCheckIn.PayDate            = obj.CheckinTime.Date;
         newCheckIn.Note               = obj.Note;
         newCheckIn.OtherServiceAmount = obj.OtherServiceAmount;
         newCheckIn.PersonNumber       = obj.PersonNumber;
         newCheckIn.RoomServiceType    = obj.RoomServiceType;
         newCheckIn.Status             = 0;//checkin
         db.InOuts.Add(newCheckIn);
         db.SaveChanges();
         if (obj.OtherServices != null)
         {
             foreach (var item in obj.OtherServices)
             {
                 if (item.IsDel != true)
                 {
                     InOut_OtherServices newService = new InOut_OtherServices();
                     newService.InOutId        = newCheckIn.InOutId;
                     newService.OtherServiceId = item.OtherServiceId;
                     newService.Quantity       = item.Quantity;
                     db.InOut_OtherServices.Add(newService);
                 }
             }
         }
         db.SaveChanges();
         Room room = db.Rooms.FirstOrDefault(r => r.RoomId == newCheckIn.RoomId);
         if (room != null)
         {
             room.Status = true;// busy
             db.SaveChanges();
         }
         var result = Json(new { success = true }, JsonRequestBehavior.AllowGet);
         return(result);
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, ErrInfo = ex }, JsonRequestBehavior.DenyGet));
     }
 }
 public JsonResult PostCheckOut(CheckOut obj)
 {
     try
     {
         var ios = from io in db.InOuts
                   where io.RoomId == obj.RoomId && io.Status == 0
                   select io;
         if (ios != null)
         {
             foreach (var checkout in ios)
             {
                 checkout.CheckinTime        = obj.CheckinTime;
                 checkout.CheckOutTime       = obj.CheckOutTime;
                 checkout.PayDate            = obj.CheckinTime.Date;
                 checkout.LengthStay         = obj.LengthStay;
                 checkout.Note               = obj.Note;
                 checkout.OtherServiceAmount = obj.OtherServiceAmount;
                 checkout.RoomServiceAmount  = obj.TotalAmount - obj.OtherServiceAmount;
                 checkout.TotalAmount        = obj.TotalAmount;
                 checkout.PersonNumber       = obj.PersonNumber;
                 checkout.RoomServiceType    = obj.RoomServiceType;
                 if (!obj.IsNotCheckOut)
                 {
                     checkout.Status = 1;//checkout
                 }
                 if (obj.OtherServices != null)
                 {
                     foreach (var item in obj.OtherServices)
                     {
                         var oldService = checkout.InOut_OtherServices.SingleOrDefault(s => s.OtherServiceId == item.OtherServiceId);
                         if (oldService != null)
                         {
                             if (item.IsDel == true)
                             {
                                 db.InOut_OtherServices.Remove(oldService);
                             }
                             else
                             {
                                 oldService.Quantity = item.Quantity;
                             }
                         }
                         else
                         {
                             if (item.IsDel != true)
                             {
                                 InOut_OtherServices newService = new InOut_OtherServices();
                                 newService.InOutId        = checkout.InOutId;
                                 newService.OtherServiceId = item.OtherServiceId;
                                 newService.Quantity       = item.Quantity;
                                 db.InOut_OtherServices.Add(newService);
                             }
                         }
                     }
                 }
             }
             db.SaveChanges();
             if (!obj.IsNotCheckOut)
             {
                 Room room = db.Rooms.FirstOrDefault(r => r.RoomId == obj.RoomId);
                 if (room != null)
                 {
                     room.Status = false; //available
                     db.SaveChanges();
                 }
             }
         }
         return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, ErrInfo = ex }, JsonRequestBehavior.DenyGet));
     }
 }