Ejemplo n.º 1
0
        public async Task <IActionResult> deliveryboyassignPost(deliveryboyAssignorderViewModel model)
        {
            if (ModelState.IsValid)
            {
                orders obj = _ordersServices.GetById(model.id);// await _usermanager.GetUserAsync(User);

                if (obj == null)
                {
                    TempData["error"] = "Order Not Found";
                }
                else
                {
                    if (string.IsNullOrEmpty(Convert.ToString(obj.deliveryboyid)))
                    {
                        obj.deliveryboyid = model.deliveryboyid;
                        obj.acceptedby    = "Admin";
                        await _ordersServices.UpdateAsync(obj);

                        var          driverdetails   = _driverRegistrationServices.GetById(model.deliveryboyid);
                        orderhistory objorderhistory = new orderhistory();
                        objorderhistory.oid         = model.id;
                        objorderhistory.placedate   = DateTime.UtcNow;
                        objorderhistory.orderstatus = "Admin assign Order to this Delivery boy." + driverdetails.name + "  . OrderID  :" + model.id;
                        await _orderhistoryServices.CreateAsync(objorderhistory);

                        #region "Notification customer and store"
                        int             customerid         = obj.customerid;
                        string          customerDeviceId   = _CustomerRegistrationservices.GetById(customerid).deviceid;
                        string          customerMsg        = driverdetails.name + " will be Delivering Your order";
                        string          customerTitle      = "Delivering Your order";
                        fcmNotification objfcmNotification = new fcmNotification();
                        objfcmNotification.customerNotification(customerDeviceId, customerMsg, "", customerTitle);

                        var    storeDeviceId = _usermanager.Users.Where(x => x.Id == obj.storeid).FirstOrDefault().deviceid;
                        string storeMsg      = "Admin Assign delivery boy " + driverdetails.name + " to this Order Id : " + model.id;
                        string storeTitle    = "Assign Deliveryboy";
                        objfcmNotification.storeNotification(storeDeviceId, storeMsg, "", storeTitle);

                        #endregion

                        TempData["success"] = "Order Assign To Delivery boy Successfully";
                        //string myJson = "{\"message\": " + "\"Order Assign To Delivery boy Successfully\"" + "}";
                        //return Ok(obj);
                    }
                    else
                    {
                        TempData["error"] = "This Order Id Already assign delivery boy";
                        //string myJson = "{\"message\": " + "\"This Order Id Already assign delivery boy\"" + "}";
                        //return BadRequest(myJson);
                    }
                }
            }
            return(RedirectToAction("test"));
        }
Ejemplo n.º 2
0
        public void AddOrderHistory(string StatusChanged, string discription, int orderid, int?empID, DateTime date)
        {
            date = DateTime.Now;
            orderhistory orderhistory = new orderhistory();

            orderhistory.date          = date;
            orderhistory.statusChanged = StatusChanged;
            orderhistory.discription   = discription;
            orderhistory.orderId       = orderid;
            orderhistory.employeeId    = empID;
            db.orderhistories.Add(orderhistory);
            db.SaveChanges();
        }
 public async Task UpdateAsync(orderhistory obj)
 {
     _context.orderhistory.Update(obj);
     await _context.SaveChangesAsync();
 }
        public async Task CreateAsync(orderhistory obj)
        {
            await _context.orderhistory.AddAsync(obj);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OrderInsertandOrderProduct(int customerid, decimal totalamount, string OrderProducts_JSONString, string promocode, string storedid, string discount, string orderstatus, string paymenttype, string paymentstatus, string deliveryaddress, string transactionid, string instruction, string customerdeliverylatitude, string customerdeliverylongitude)
        {
            var paramter = new DynamicParameters();

            paramter.Add("@customerid", customerid);
            var orderlist = _ISP_Call.List <orderselectallViewModel>("checkCustomerOrderComplete", paramter);

            bool flg = true;

            foreach (var item in orderlist)
            {
                if (item.orderstatus == "completedorders" || item.orderstatus == "cancelledorders")
                {
                }
                else
                {
                    flg = false;
                }
            }
            if (flg == false)
            {
                string myJson = "{'message': 'First Complete your Previous Orders'}";
                return(Ok(myJson));
            }
            else
            {
                //var customer = CustomerRegistrationservices.GetById(id);
                if (customerid == 0)
                {
                    return(NotFound());
                }
                else
                {
                    orders objorders = new orders();
                    objorders.customerid = customerid;
                    objorders.amount     = totalamount;
                    //objorders.placedate = DateTime.UtcNow;
                    objorders.placedate     = DateTime.Now;
                    objorders.paymentstatus = paymentstatus;
                    objorders.orderstatus   = orderstatus;

                    objorders.discount        = Convert.ToDecimal(discount);
                    objorders.storeid         = storedid;
                    objorders.deliveryaddress = deliveryaddress;
                    objorders.paymenttype     = paymenttype;
                    objorders.promocode       = promocode;
                    objorders.transactionid   = transactionid;
                    objorders.instructions    = instruction;
                    // objorders.propmocode = promocode;

                    objorders.customerdeliverylatitude  = customerdeliverylatitude;
                    objorders.customerdeliverylongitude = customerdeliverylongitude;
                    //                , deliveryboyid, paymentstatus, orderstatus, isdeleted, discount, storeid,
                    //deliveryaddress, paymenttype, promocode

                    objorders.storeid = storedid;
                    //if (promocode == ""|| storedid=="")
                    //{
                    //    objorders.discount = 0;
                    //}
                    //else
                    //{
                    //    objorders.discount = _storedetailsServices.GetAll().Where(x => x.storeid == storedid&&x.promocode==promocode).FirstOrDefault().discount;
                    //}
                    int OrderProductAdd = 0;
                    int OrderId         = 0;
                    var dtOrderProducts = JsonConvert.DeserializeObject <DataTable>(OrderProducts_JSONString);
                    if (dtOrderProducts != null)
                    {
                        if (dtOrderProducts.Rows.Count > 0)
                        {
                            OrderId = await _ordersServices.CreateAsync(objorders);

                            if (OrderId > 0)
                            {
                                for (int i = 0; i < dtOrderProducts.Rows.Count; i++)
                                {
                                    orderproducts objorderproduct = new orderproducts();
                                    objorderproduct.oid       = OrderId;
                                    objorderproduct.pid       = Convert.ToInt32(dtOrderProducts.Rows[i]["productid"]);
                                    objorderproduct.qty       = Convert.ToInt64(dtOrderProducts.Rows[i]["quantites"]);
                                    objorderproduct.price     = Convert.ToInt64(dtOrderProducts.Rows[i]["productprice"]);
                                    objorderproduct.isdeleted = false;
                                    await _orderproductServices.CreateAsync(objorderproduct);



                                    //id, oid, placedate, orderstatus
                                    //   id, oid, pid, qty, price, isdeleted
                                    //[{"productid":"1","productprice":"500","quantites":10},{"productid":"2","productprice":"500","quantites":10}]
                                }
                            }


                            orderhistory objorderhistory = new orderhistory();
                            objorderhistory.oid         = OrderId;
                            objorderhistory.placedate   = DateTime.UtcNow;
                            objorderhistory.orderstatus = "place Order";
                            await _orderhistoryServices.CreateAsync(objorderhistory);

                            var users = await _usermanager.FindByIdAsync(storedid);

                            string storeDeviceId = users.deviceid;
                            if (storeDeviceId == null || storeDeviceId.ToString().Trim() == "")
                            {
                            }
                            else
                            {
                                string sResponseFromServer = string.Empty, finalResult = string.Empty;
                                try
                                {
                                    WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                                    tRequest.Method = "post";
                                    //serverKey - Key from Firebase cloud messaging server   customer
                                    //tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAAxJW0hf8:APA91bG1ipIsec--9KYV5bv6kagmly4PfFHH-UCLsbsqVxuZsoBPvw-AuRy_DhBa0sT2raF5D0DJhbx8G59lKV2fg6WbUDMzvWsyqxlQLjz-Epk3p04lujWk1c-enH5o3CLq_ejPVqr4"));
                                    //store change 9.9.20
                                    //tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAAr0cwgUE:APA91bEs5PB48LpheJuGQOJi8jENylDdtBgGA5tcHFY2Kbz4-FwNLocAN8z7X7c4ADuP6vA7MSE3M6hx5OHp12iFt0yb7zfHO16c7mlgnppsEOFY8J4WRfpOUI-RkbXBLBwMqYwwDyYX"));
                                    ////Sender Id - From firebase project setting
                                    //tRequest.Headers.Add(string.Format("Sender: id={0}", "752813637953"));

                                    tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAA-grvO4U:APA91bG1TeBl5uVNLOHGyjSYSJ_-PZiOFKeSUkjhx4do27iECafs1dVdAyhE6-QvMDON6xrz-YOa10tMgFdmy_w1amPXVHsXLWrAggDh8oU0c1F8CvdBW6aGc1wrqP8OlQ86ZzxzkTuS"));
                                    //Sender Id - From firebase project setting
                                    tRequest.Headers.Add(string.Format("Sender: id={0}", "1073925274501"));
                                    tRequest.ContentType = "application/json";
                                    var payload = new
                                    {
                                        to                = storeDeviceId,
                                        priority          = "high",
                                        content_available = true,
                                        notification      = new
                                        {
                                            //body = "New Order No. - " + OrderId + " insert",
                                            body  = "Order Received",
                                            title = "New Order",
                                            badge = 1
                                        },
                                        data = new
                                        {
                                            key1 = "AAAA-grvO4U:APA91bG1TeBl5uVNLOHGyjSYSJ_-PZiOFKeSUkjhx4do27iECafs1dVdAyhE6-QvMDON6xrz-YOa10tMgFdmy_w1amPXVHsXLWrAggDh8oU0c1F8CvdBW6aGc1wrqP8OlQ86ZzxzkTuS",
                                            key2 = "1073925274501"
                                        }
                                    };

                                    //string postbody = JsonConvert.SerializeObject(payload).ToString();

                                    var    serializer = new JavaScriptSerializer();
                                    var    postbody   = serializer.Serialize(payload);
                                    Byte[] byteArray  = Encoding.UTF8.GetBytes(postbody);
                                    tRequest.ContentLength = byteArray.Length;
                                    using (Stream dataStream = tRequest.GetRequestStream())
                                    {
                                        dataStream.Write(byteArray, 0, byteArray.Length);
                                        using (WebResponse tResponse = tRequest.GetResponse())
                                        {
                                            using (Stream dataStreamResponse = tResponse.GetResponseStream())
                                            {
                                                if (dataStreamResponse != null)
                                                {
                                                    using (StreamReader tReader = new StreamReader(dataStreamResponse))
                                                    {
                                                        sResponseFromServer = tReader.ReadToEnd();
                                                        //result.Response = sResponseFromServer;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                catch (Exception ex)
                                {
                                    string s = ex.Message;
                                    // throw ex;
                                }
                                // return Ok(sResponseFromServer);
                            }
                            //---sent notification to admin----------------
                            var users1 = await _usermanager.FindByIdAsync("6852cc0f-f62e-42a4-8dc7-5fd0478ba197");

                            string          deviceid1 = users1.deviceid;
                            fcmNotification obj       = new fcmNotification();
                            obj.adminNotification(deviceid1, "Order Received", "", "New Order");


                            //manager Notification
                            var paramterManager = new DynamicParameters();
                            paramterManager.Add("@storeid", storedid);
                            var managerList = _ISP_Call.List <GetManagerList>("GetManagerList", paramterManager);


                            foreach (var item in managerList)
                            {
                                if (item.deviceid == null || item.deviceid.ToString().Trim() == "")
                                {
                                    obj.adminNotification(item.deviceid, "Order Received", "", "New Order");
                                }
                            }
                        }
                    }
                    if (OrderId == 0)
                    {
                        return(BadRequest());
                    }
                    else
                    {
                        var orders = _ordersServices.GetById(OrderId);
                        return(Ok(orders));
                    }
                    // customerid, amount, placedate, deliveryboyid, paymentstatus, orderstatus, isdeleted, isactive
                    //customer.deviceid = deviceId;
                    //await CustomerRegistrationservices.UpdateAsync(customer);

                    //if (id < 0)
                    //{
                    //    return BadRequest();
                    //}
                    //else
                    //{

                    //    return Ok(customer);
                    //}
                }
                return(BadRequest());
            }
        }