예제 #1
0
        public messageModel save_status(bookCarDetailModel 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");
                    }

                    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_approve_admin"))
                    {
                        save_type = "6";
                    }
                    else if (value.method.Equals("save_approve_sh"))
                    {
                        save_type = "7";
                    }

                    if (save_type == "3" || save_type == "6" || save_type == "7")
                    {
                        var allCarList    = context.BOOK_CAR.ToList();
                        var bookingDeatil = allCarList.SingleOrDefault(a => a.BC_ID.ToString() == value.id);
                        if (bookingDeatil != null)
                        {
                            System.Data.Entity.Core.Objects.ObjectParameter myOutputParam_sts = new System.Data.Entity.Core.Objects.ObjectParameter("r_sts", typeof(String));
                            System.Data.Entity.Core.Objects.ObjectParameter myOutputParam_msg = new System.Data.Entity.Core.Objects.ObjectParameter("r_msg", typeof(String));

                            var date_from = DateTime.ParseExact(bookingDeatil.bc_start_date.Value.ToString("dd/MM/yyyy") + " " + bookingDeatil.bc_start_time, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
                            var date_to   = DateTime.ParseExact(bookingDeatil.bc_stop_date.Value.ToString("dd/MM/yyyy") + " " + bookingDeatil.bc_stop_time, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);

                            string s_date_from = date_from.ToString("yyyy-MM-dd") + " " + date_from.ToString("HH:mm:ss", new CultureInfo("th-TH"));
                            string s_date_to   = date_to.ToString("yyyy-MM-dd") + " " + date_to.ToString("HH:mm:ss", new CultureInfo("th-TH"));
                            context.sp_bookcar_availability(s_date_from, s_date_to, bookingDeatil.MCA_ID.ToString(), value.id, myOutputParam_sts, myOutputParam_msg);
                            if (myOutputParam_sts.Value != null)
                            {
                                if (myOutputParam_sts.Value.ToString() == "E")
                                {
                                    throw new Exception(myOutputParam_msg.Value.ToString());
                                }
                                else
                                {
                                    int ret = context.sp_bookcar_save_status(value.id, save_type, value.remark, userId);
                                    result.status  = "S";
                                    result.message = "";
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("Data not Found");
                        }
                    }
                    else
                    {
                        int ret = context.sp_bookcar_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);
        }