public Response GetOrderDetails(string user_id, GetCriteria getCriteria)
        {
            try
            {
                // Get Order Data
                OrdersDetails orderDetails = new OrderRepository.OrderRepository(language).GetOrderDetails(Convert.ToInt32(user_id), getCriteria.order_id, getCriteria.lat, getCriteria.lang, getCriteria.offer_id);

                // Get Car Images
                try
                {
                    List <string> carImageList = new VehicleRepository.VehicleRepository(language).GetCarImages(getCriteria.order_id, orderDetails.order.ORDERTYPE_ID);
                    orderDetails.media = carImageList;
                }
                catch (EmptyViewException)
                {
                    orderDetails.media = new List <string>();
                }
                catch (Exception ex)
                {
                    orderDetails.media = new List <string>();
                }

                return(new Response(true, Messages.GetMessage(language, TypeM.ACCIDENT, orderM.Order_DATA_FOUND), orderDetails));
            }
            catch (EmptyViewException EmptyViewException)
            {
                return(new Response(false, EmptyViewException.RespMessage));
            }
            catch (Exception ex)
            {
                return(new Response(false, Messages.GetMessage(language, Messages.TypeM.DEFAULT, Messages.defaultM.UNEXPERROR)));
            }
        }
        public Response GetOrderLists(int orderType_id)
        {
            try
            {
                //Prepare date

                List <InfoWindow> dropLists = new OrderRepository.OrderRepository(language).GetOrderListDetails(orderType_id);



                return(new Response(true, Messages.GetMessage(language, TypeM.DEFAULT, defaultM.DATAGOT), dropLists));
            }
            catch (EmptyViewException EmptyViewException)
            {
                return(new Response(true, EmptyViewException.RespMessage, EmptyViewException, new List <object>()));
            }
            catch (InsertException InsertException)
            {
                return(new Response(false, InsertException.RespMessage, InsertException, new List <object>()));
            }
            catch (Exception ex)
            {
                return(new Response(false, Messages.GetMessage(language, TypeM.DEFAULT, defaultM.UNEXPERROR), ex, new List <object>()));
            }
        }
        public Response DeleteRequest(int order_id)
        {
            try
            {
                bool          ImgStatus = true;
                List <string> imgUris   = new OrderRepository.OrderRepository(language).GetOrderAllMedia(order_id);
                if (new OrderRepository.OrderRepository(language).DeleteRequestByOrderId(order_id))
                {
                    foreach (string imgUri in imgUris)
                    {
                        try
                        {
                            if (!new UploadRepository(language).DeleteImage(imgUri))
                            {
                                ImgStatus = false;
                            }
                        }catch
                        {
                        }
                    }

                    if (ImgStatus)
                    {
                        return(new Response(true, Messages.GetMessage(language, TypeM.ACCIDENT, orderM.REQUEST_DELETED)));
                    }
                    else
                    {
                        return(new Response(false, Messages.GetMessage(language, TypeM.ACCIDENT, orderM.REQUEST_NOT_DELETED)));
                    }
                }

                else
                {
                    throw new DeleteException(language);
                }
            }
            catch (DeleteException DeleteException)
            {
                return(new Response(false, DeleteException.RespMessage));
            }
            catch (EmptyViewException EmptyViewException)
            {
                return(new Response(false, EmptyViewException.RespMessage));
            }
            catch (Exception ex)
            {
                return(new Response(false, Messages.GetMessage(language, TypeM.DEFAULT, defaultM.UNEXPERROR), ex.Message.ToString()));
            }
        }
 public Response GetOrderType(string lang)
 {
     try
     {
         List <OrderType> orderTypes = new OrderRepository.OrderRepository(language).GetOrderType(lang);
         return(new Response(true, Messages.GetMessage(lang, Messages.TypeM.DEFAULT, defaultM.DATAGOT), orderTypes));
     }
     catch (EmptyViewException EmptyViewException)
     {
         return(new Response(true, EmptyViewException.RespMessage, EmptyViewException, new List <string>()));
     }
     catch (Exception ex)
     {
         return(new Response(false, Messages.GetMessage(lang, Messages.TypeM.DEFAULT, Messages.defaultM.UNEXPERROR)));
     }
 }
        //public Response GetLastWorkshopLocation(string accessToken)
        //{
        //    try
        //    {
        //        int user_id = new UserRepository.UserRepository().GetUserIdByAccessToken(accessToken);
        //        WorkshopDb workshop = new AccidentRepository.AccidentRepository().GetLastWorkshopLocation(user_id);
        //        return new Response(true, Messages.DATAGOT_AR, Messages.DATAGOT_EN, workshop);
        //    }

        //    catch (EmptyViewException EmptyViewException)
        //    {
        //        return new Response(false, EmptyViewException.messageAr, EmptyViewException.messageEn, EmptyViewException.Message, new List<string>());
        //    }
        //    catch (Exception ex)
        //    {
        //        return new Response(false, Messages.UNEXPERROR_AR, Messages.UNEXPERROR_EN, ex.Message, new List<string>());
        //    }
        //}

        public Response GetDamagesType(  )
        {
            try
            {
                List <DamagesType> damagesTypes = new OrderRepository.OrderRepository(language).GetDamagesType();
                return(new Response(true, Messages.GetMessage(language, TypeM.DEFAULT, defaultM.DATAGOT), damagesTypes));
            }
            catch (EmptyViewException EmptyViewException)
            {
                return(new Response(true, EmptyViewException.RespMessage, EmptyViewException, new List <string>()));
            }
            catch (Exception ex)
            {
                return(new Response(false, Messages.GetMessage(language, TypeM.DEFAULT, defaultM.UNEXPERROR), ex.Message.ToString()));
            }
        }
 public Response GetPersonRequests(string user_id)
 {
     try
     {
         int userId = Convert.ToInt32(user_id);
         List <UserRequestCriteria> requestCriterias = new OrderRepository.OrderRepository(language).GetRequestsByUser_id(userId);
         return(new Response(true, Messages.GetMessage(language, Messages.TypeM.DEFAULT, defaultM.DATAGOT), requestCriterias));
     }
     catch (EmptyViewException EmptyViewException)
     {
         return(new Response(true, EmptyViewException.RespMessage, EmptyViewException, new List <string>()));
     }
     catch (Exception ex)
     {
         return(new Response(false, Messages.GetMessage(language, Messages.TypeM.DEFAULT, Messages.defaultM.UNEXPERROR), new List <string>()));
     }
 }
        public Response StoreOrderData(CarInfoOrder carInfoOrder, string user_id)
        {
            try
            {
                // Insert Order Data To DB
                if (new OrderRepository.OrderRepository(language).InsertOrderData(carInfoOrder, user_id))
                {
                    int order_id = new OrderRepository.OrderRepository(language).GetOrderIdByUserId(Convert.ToInt32(user_id));

                    // Insert order_details_assigns
                    foreach (int assign in carInfoOrder.orderDetailsIds)
                    {
                        new OrderRepository.OrderRepository(language).InsertOrderDetailAssign(order_id, assign);
                    }

                    //----------------------------



                    bool      imageStatus    = true;
                    Exception imageException = new Exception();



                    // Store Images
                    int i = 0;
                    foreach (string image in carInfoOrder.images)
                    {
                        string url = "";
                        i++;
                        string ImageName = "images/OrderImages/" + i + "_" + carInfoOrder.OrderIdentity + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".png";



                        url = new UploadRepository(language).StoreImage(image, ImageName);

                        if (url != "")
                        {
                            try
                            {
                                new OrderRepository.OrderRepository(language).InsertOrderPictureUrl(ImageName, 1, order_id);
                            }
                            catch (InsertException ex)
                            {
                                imageStatus    = false;
                                imageException = ex;
                            }
                        }
                    }

                    //----------------



                    // check If Image Was Inserted And Response with This Data
                    if (imageStatus)
                    {
                        return(new Response(imageStatus, Messages.GetMessage(language, TypeM.ACCIDENT, orderM.IMAGE_Order_STORE), order_id));
                    }
                    else
                    {
                        return(new Response(imageStatus, Messages.GetMessage(language, TypeM.ACCIDENT, orderM.IMAGE_Order_ERROR), imageException, order_id));
                    }
                    ///-------------------------
                }
                else
                {
                    throw new InsertException(language);
                }
            }
            catch (EmptyViewException EmptyViewException)
            {
                return(new Response(false, EmptyViewException.RespMessage, EmptyViewException.ErrorMessage));
            }
            catch (InsertException InsertException)
            {
                return(new Response(false, InsertException.RespMessage, InsertException.ErrorMessage));
            }
            catch (UpdateException UpdateException)
            {
                return(new Response(false, UpdateException.RespMessage, UpdateException.ErrorMessage));
            }
            catch (Exception ex)
            {
                var st = new StackTrace(ex, true);
                // Get the top stack frame
                var frame = st.GetFrame(0);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                return(new Response(false, Messages.GetMessage(language, TypeM.DEFAULT, defaultM.UNEXPERROR) + ex.Message.ToString(), ex.Message.ToString() + "::: line NO:: " + line));
            }
        }
        public ActionResult <Response> StoreOrderDataAsync([FromQuery(Name = "lang")] string lang, [FromForm] string accessToken, [FromForm] string carId,
                                                           [FromForm] string orderType, [FromForm] string cityId, [FromForm] string locationX, [FromForm] string locationY, [FromForm] string orderDetailsIds, [FromForm] string note, [FromForm] string images)
        {
            List <string> imgs           = new List <string>();
            List <int>    orderassignIds = new List <int>();

            // Check If List Is NULL
            if (images != null)
            {
                imgs = JsonConvert.DeserializeObject <List <string> >(images);
            }

            ////NO car Service
            //if (carId == null)
            //    carId = "-1";


            // Check If List Is NULL
            if (orderDetailsIds != null)
            {
                orderassignIds = JsonConvert.DeserializeObject <List <int> >(orderDetailsIds);
            }



            // MAPPING DATA
            CarInfoOrder carInfoOrder = new CarInfoOrder();

            carInfoOrder.accessToken = accessToken;


            if (carId != null && carId != "" && carId != "0")
            {
                carInfoOrder.carId = Convert.ToInt32(carId);
            }
            else
            {
                carInfoOrder.carId = null;
            }


            if (cityId != null && cityId != "" && cityId != "0" && cityId != "-1")
            {
                carInfoOrder.cityId = Convert.ToInt32(cityId);
            }

            else
            {
                carInfoOrder.cityId = 1;
            }


            if (orderType != null)
            {
                carInfoOrder.orderType = Convert.ToInt32(orderType);
            }
            else
            {
                carInfoOrder.orderType = 1;
            }

            carInfoOrder.locationX = Convert.ToDouble(locationX);
            carInfoOrder.locationY = Convert.ToDouble(locationY);

            if (orderassignIds == null)
            {
                carInfoOrder.orderDetailsIds = new List <int>();
            }
            else
            {
                carInfoOrder.orderDetailsIds = orderassignIds;
            }

            carInfoOrder.note = note;

            if (imgs == null)
            {
                carInfoOrder.images = new List <string>();
            }
            else
            {
                carInfoOrder.images = imgs;
            }



            //check AccessToken
            string user_id = new UserService(lang).CheckAccessTokenUser(carInfoOrder.accessToken);

            carInfoOrder.OrderIdentity = new HelperRepository().generateIds((int)Enums.CreationNumberCode.order, DateTime.Now);

            if (user_id != null)
            {
                // STORE ACCIDENT DATA
                Response res      = new OrderService(lang).StoreOrderData(carInfoOrder, user_id);
                var      order_id = res.innerData;
                res.innerData = new  object();


                //Send Notification To ALL Admin When New Request Created
                if (res.status)
                {
                    try
                    {
                        //Get All Suppliers Ids
                        List <int> users = new UserRepository.UserRepository(lang).GetAllAdminIds();
                        foreach (int user in users)
                        {
                            try
                            {
                                new ServicesRepository(lang).SendNotiAllDevices(user, Messages.GetMessage(lang, TypeM.notifyM, notifyM.NOTI_TITLE),
                                                                                Messages.GetMessage(lang, TypeM.notifyM, notifyM.NOTI_NEW_ORDER), 1);
                            }
                            catch
                            {
                                ;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        new Response(false, ex.Message, ex.Message);
                    }
                }


                // GET ACCIDENT ID
                //int order_id = new OrderRepository.OrderRepository(lang).GetOrderIdByUserId(carInfoOrder.carId);

                if (res.status)
                {
                    // Store Video Accident
                    try
                    {
                        var file = Request.Form.Files["video"];

                        // Check if Null So , Do not Store Video
                        if (file == null)
                        {
                            return(res);
                        }


                        var folderName = Path.Combine("Resources", "Images");
                        var pathToSave = @"../dealxImages\videos\orders";//Path.Combine(Directory.GetCurrentDirectory(), folderName);

                        if (file.Length > 0)
                        {
                            var  fileName       = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"') + ".mp4";
                            var  fullPath       = Path.Combine(pathToSave, fileName);
                            var  dbPath         = Path.Combine(folderName, fileName);
                            bool UrlVideoStatus = false;
                            using (var stream = new FileStream(fullPath, FileMode.Create))
                            {
                                file.CopyTo(stream);

                                UrlVideoStatus = new OrderRepository.OrderRepository(lang).InsertOrderPictureUrl("videos/orders/" + fileName, 2, Convert.ToInt32(order_id));
                            }
                            if (UrlVideoStatus)
                            {
                                return(res);
                            }
                            else
                            {
                                return(new Response(false, Messages.GetMessage(lang, TypeM.ACCIDENT, orderM.VIDEO_Order_ERROR)));
                            }
                        }
                        else
                        {
                            return(new Response(false, Messages.GetMessage(lang, TypeM.ACCIDENT, orderM.VIDEO_Order_ERROR)));
                        }
                    }
                    catch (Exception ex)
                    {
                        return(new Response(false, Messages.GetMessage(lang, TypeM.ACCIDENT, orderM.VIDEO_Order_ERROR), ex.Message));
                    }
                }
                else
                {
                    return(res);
                }
            }

            else
            {
                return(new Response(false, Messages.GetMessage(lang, TypeM.DEFAULT, defaultM.WRONG_ACCESS_TOKEN)));
            }
        }