示例#1
0
        public messageModel save_status(bookRoomDetailModel value)
        {
            messageModel result = new messageModel();

            try
            {
                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));
                using (var context = new StandardCanEntities())
                {
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }

                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);

                    context.interface_log.Add(new interface_log
                    {
                        ID          = 1,
                        data_log    = json,
                        module      = "book_room_save",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    string save_type = "";
                    if (value.method.Equals("save_cancel"))
                    {
                        save_type = "0";
                    }
                    else if (value.method.Equals("save_approve"))
                    {
                        save_type = "3";
                    }
                    else if (value.method.Equals("save_reject"))
                    {
                        save_type = "4";
                    }
                    else if (value.method.Equals("save_revise"))
                    {
                        ///TODO Draft
                        save_type = "1";
                    }

                    if (save_type == "3")
                    {
                        var allRoomList   = context.BOOK_ROOM.ToList();
                        var bookingDeatil = allRoomList.SingleOrDefault(a => a.BR_ID.ToString() == value.id);
                        if (bookingDeatil != null)
                        {
                            var dupTime = 0;
                            //var chkSameDate = allRoomList.Where(a => a.br_date == bookingDeatil.br_date && a.MRM_ID == bookingDeatil.MRM_ID && a.br_status == 3).ToList();
                            //var start_time = DateTime.ParseExact(bookingDeatil.br_start_time, "HH:mm", CultureInfo.InvariantCulture);
                            //var stop_time = DateTime.ParseExact(bookingDeatil.br_stop_time, "HH:mm", CultureInfo.InvariantCulture);
                            //foreach (var item in chkSameDate)
                            //{
                            //    var _itemStart_time = DateTime.ParseExact(item.br_start_time, "HH:mm", CultureInfo.InvariantCulture);
                            //    var _itemStop_time = DateTime.ParseExact(item.br_stop_time, "HH:mm", CultureInfo.InvariantCulture);

                            //    if(stop_time > _itemStart_time)
                            //    {
                            //        dupTime++;
                            //    }
                            //}
                            if (dupTime == 0)
                            {
                                int ret = context.sp_bookroom_save_status(value.id, save_type, value.remark, userId);
                                result.status  = "S";
                                result.message = "";
                            }
                            else
                            {
                                throw new Exception("ห้องนี้ในช่วงเวลานี้ได้ถูกจองแล้ว");
                            }
                        }
                        else
                        {
                            throw new Exception("Data not Found");
                        }
                    }
                    else
                    {
                        int ret = context.sp_bookroom_save_status(value.id, save_type, value.remark, userId);
                        result.status  = "S";
                        result.message = "";
                    }
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }