public async Task <JsonResult> PositionDatatable(JQueryDataTableParamModel param, string IMEI, DateTime startDate, DateTime endDate)
        {
            try
            {
                HttpClient httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await httpClient.GetAsync
                                                   (ShareDataConnection.IPconnection + "api/position/getAllPosition?deviceId=" + IMEI + "&startDate=" + startDate + "&endDate=" + endDate);

                if (response.StatusCode.ToString() == "OK")
                {
                    var listPosition = JsonConvert.DeserializeObject <List <Product_position> >(response.Content.ReadAsStringAsync().Result);
                    var positionList = listPosition.AsEnumerable()
                                       .Where(a => (string.IsNullOrEmpty(param.sSearch) || StringConvert.EscapeName(a.DeviceId).ToLower()
                                                    .Contains(StringConvert.EscapeName(param.sSearch).ToLower())));
                    int count = 1;
                    var rp    = positionList
                                .Skip(param.iDisplayStart).Take(param.iDisplayLength)
                                .Select(p => new IConvertible[]
                    {
                        count++,
                        p.CreatedDate.ToShortDateString() + " " + p.CreatedDate.ToShortTimeString(),
                        p.Id,
                        p.Latitude,
                        p.Longitude,
                        p.Altitude,
                    });
                    var total = positionList.Count();
                    return(Json(new
                    {
                        sEcho = param.sEcho,
                        iTotalRecords = total,
                        iTotalDisplayRecords = total,
                        aaData = rp
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        sEcho = param.sEcho,
                        iTotalRecords = 0,
                        iTotalDisplayRecords = 0,
                        aaData = new List <Product_position>()
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <Product_position>()
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult UserDatatable(JQueryDataTableParamModel param)
        {
            try
            {
                var userService = this.Service <IUserService>();
                var listUsers   = userService.GetAllUser();
                if (listUsers == null)
                {
                    return(Json(new
                    {
                        sEcho = param.sEcho,
                        iTotalRecords = 0,
                        iTotalDisplayRecords = 0,
                        aaData = new List <UserViewModel>()
                    }, JsonRequestBehavior.AllowGet));
                }
                var userList = listUsers.AsEnumerable()
                               .Where(a => (string.IsNullOrEmpty(param.sSearch) || StringConvert.EscapeName(a.Username).ToLower()
                                            .Contains(StringConvert.EscapeName(param.sSearch).ToLower())));
                int count = 1;

                var rp = userList
                         .Skip(param.iDisplayStart).Take(param.iDisplayLength)
                         .Select(p => new IConvertible[]
                {
                    count++,
                    p.Username,
                    p.Fullname,
                    p.Devices.Count,
                    String.Format("{0:dd/ MM/ yyyy}", p.ExpireDate),
                    (p.Licienses.Where(q => q.UserId == p.Id && q.IsUse).Count()) == 0 ? 0 : p.Licienses.Where(q => q.UserId == p.Id && q.IsUse).FirstOrDefault().PackageId,
                    p.Active,
                    p.Id,
                });
                var total = listUsers.Count();
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = total,
                    iTotalDisplayRecords = total,
                    aaData = rp
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <UserViewModel>()
                }, JsonRequestBehavior.AllowGet));
            }
        }
 public JsonResult DeviceDatatable(JQueryDataTableParamModel param)
 {
     try
     {
         var  userService   = this.Service <IUserService>();
         User user          = userService.GetByUsername(Session["Username"].ToString());
         var  deviceService = this.Service <IDeviceService>();
         var  listDevices   = deviceService.getByUserId(user.Id);
         if (listDevices == null)
         {
             return(Json(new
             {
                 sEcho = param.sEcho,
                 iTotalRecords = 0,
                 iTotalDisplayRecords = 0,
                 aaData = listDevices
             }, JsonRequestBehavior.AllowGet));
         }
         var deviceList = listDevices.AsEnumerable()
                          .Where(a => (string.IsNullOrEmpty(param.sSearch) || StringConvert.EscapeName(a.Name).ToLower()
                                       .Contains(StringConvert.EscapeName(param.sSearch).ToLower()) ||
                                       StringConvert.EscapeName(a.Id).ToLower()
                                       .Contains(StringConvert.EscapeName(param.sSearch).ToLower())));
         int count = 1;
         var rp    = deviceList
                     .Skip(param.iDisplayStart).Take(param.iDisplayLength)
                     .Select(p => new IConvertible[]
         {
             count++,
             p.Id,
             p.Name,
             p.Active,
         });
         var total = listDevices.Count();
         return(Json(new
         {
             sEcho = param.sEcho,
             iTotalRecords = total,
             iTotalDisplayRecords = total,
             aaData = rp
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new
         {
             sEcho = param.sEcho,
             iTotalRecords = 0,
             iTotalDisplayRecords = 0,
             aaData = new List <DeviceViewModel>()
         }, JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult MapDatatable(JQueryDataTableParamModel param)
        {
            try
            {
                var mapService = this.Service <IMapService>();
                var maps       = mapService.GetActive();

                if (maps != null)
                {
                    var mapList = maps.AsEnumerable()
                                  .Where(a => (string.IsNullOrEmpty(param.sSearch) || StringConvert.EscapeName(a.Name).ToLower()
                                               .Contains(StringConvert.EscapeName(param.sSearch).ToLower())));
                    int count = 1;
                    var rp    = mapList
                                .Skip(param.iDisplayStart).Take(param.iDisplayLength)
                                .Select(p => new IConvertible[]
                    {
                        count++,
                        p.Name,
                        p.Floor,
                        p.MapUrl,
                        p.Altitude,
                        p.Id,
                    });
                    var total = maps.Count();
                    return(Json(new
                    {
                        sEcho = param.sEcho,
                        iTotalRecords = total,
                        iTotalDisplayRecords = total,
                        aaData = rp
                    }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <Building>()
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <Building>()
                }, JsonRequestBehavior.AllowGet));
            }
        }
示例#5
0
        public HttpResponseMessage SearchCustomerInfo(string keyword)
        {
            try
            {
                var customerService = this.Service <ICustomerService>();
                var contactService  = this.Service <IContactService>();

                var listCustomers = customerService.getAllCustomers().AsEnumerable();
                var listContacts  = contactService.getAllContact().AsEnumerable();

                //Validation keyword
                if (!string.IsNullOrWhiteSpace(keyword))
                {
                    //Search by keyword
                    listCustomers = listCustomers.Where(a =>
                                                        StringConvert.EscapeName(a.CusName).ToLower().Contains(StringConvert.EscapeName(keyword).ToLower()));

                    var listCustomersWithStageId = listCustomers.Join(listContacts,
                                                                      customer => customer.CusId,
                                                                      contact => contact.cusID,
                                                                      (customer, contact) => new {
                        cusId   = customer.CusId,
                        cusName = customer.CusName,
                        phone   = customer.CusPhone,
                        stageId = contact.stageID.GetValueOrDefault()
                    });

                    return(new HttpResponseMessage()
                    {
                        Content = new JsonContent(listCustomersWithStageId)
                    });
                }

                return(new HttpResponseMessage()
                {
                    Content = new JsonContent(null)
                });
            }
            catch (Exception e)
            {
                return(new HttpResponseMessage()
                {
                    Content = new JsonContent(e.Message)
                });
            }
        }
        public JsonResult PositionDatatable(JQueryDataTableParamModel param, string IMEI, DateTime startDate, DateTime endDate)
        {
            try
            {
                var deviceService = this.Service <IDeviceService>();
                var device        = deviceService.GetById(IMEI);

                if (device != null)
                {
                    IProduct_positionService      positionService = this.Service <IProduct_positionService>();
                    IQueryable <Product_position> listPosition    = positionService.getListById(IMEI, startDate, endDate);
                    if (listPosition == null)
                    {
                        return(Json(new
                        {
                            sEcho = param.sEcho,
                            iTotalRecords = 0,
                            iTotalDisplayRecords = 0,
                            aaData = new List <Product_position>()
                        }, JsonRequestBehavior.AllowGet));
                    }
                    var positionList = listPosition.AsEnumerable()
                                       .Where(a => (string.IsNullOrEmpty(param.sSearch) || StringConvert.EscapeName(a.DeviceId).ToLower()
                                                    .Contains(StringConvert.EscapeName(param.sSearch).ToLower())));
                    int count = 1;
                    var rp    = positionList
                                .Skip(param.iDisplayStart).Take(param.iDisplayLength)
                                .Select(p => new IConvertible[]
                    {
                        count++,
                        p.CreatedDate.ToShortDateString() + " " + p.CreatedDate.ToShortTimeString(),
                        p.Id,
                        p.Latitude,
                        p.Longitude,
                        p.Altitude,
                    });
                    var total = positionList.Count();
                    return(Json(new
                    {
                        sEcho = param.sEcho,
                        iTotalRecords = total,
                        iTotalDisplayRecords = total,
                        aaData = rp
                    }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <Product_position>()
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <Product_position>()
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <JsonResult> HistoryDatatable(JQueryDataTableParamModel param, DateTime startDate, DateTime endDate)
        {
            try
            {
                HttpClient httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage responseUser = await httpClient.GetAsync
                                                       (ShareDataConnection.IPconnection + "api/user/GetUserInfo?username="******"Username"].ToString());

                var user = JsonConvert.DeserializeObject <User>(responseUser.Content.ReadAsStringAsync().Result);
                HttpResponseMessage response = await httpClient.GetAsync
                                                   (ShareDataConnection.IPconnection + "api/order/getAllHistory?userId=" + user.Id + "&startDate=" + startDate + "&endDate=" + endDate);

                if (response.StatusCode.ToString() == "OK")
                {
                    var listHistorys = JsonConvert.DeserializeObject <List <HistoryViewModel> >(response.Content.ReadAsStringAsync().Result);
                    var historyList  = listHistorys.AsEnumerable()
                                       .Where(a => (string.IsNullOrEmpty(param.sSearch) || StringConvert.EscapeName(a.LicenseType.Price + "").ToLower()
                                                    .Contains(StringConvert.EscapeName(param.sSearch).ToLower())));
                    int count = 1;
                    var rp    = historyList
                                .Skip(param.iDisplayStart).Take(param.iDisplayLength)
                                .Select(p => new IConvertible[]
                    {
                        count++,
                        p.username,
                        p.CreatedDate.ToShortDateString() + " " + p.CreatedDate.ToShortTimeString(),
                        p.BuyDate + " ngày",
                        p.Price + " $",
                    });
                    var total = listHistorys.Count();
                    return(Json(new
                    {
                        sEcho = param.sEcho,
                        iTotalRecords = total,
                        iTotalDisplayRecords = total,
                        aaData = rp
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        sEcho = param.sEcho,
                        iTotalRecords = 0,
                        iTotalDisplayRecords = 0,
                        aaData = new List <History>()
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <History>()
                }, JsonRequestBehavior.AllowGet));
            }
        }