public void TemperatureHistory_WithSessionNotNull_ExpectOk()
        {
            //Arrange
            String expectedView = "TemperatureHistory";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(string.Format("{0} {1}", "FName", "LName"));
            _temperatureController.ControllerContext = _controllerContext.Object;
            TemperatureSearchModel temperatureSearchMl = new TemperatureSearchModel
            {
                DeviceId = 21,
                LogicalDeviceId = "ChetuTestDeviceId",
                ReadingTimeFrom = "2015-08-04 11:01:17",
                ReadingTimeTo = "2016-02-02 11:01:17"
            };
            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.TemperatureSortField.ReadingTime.ToString(),
                SortDirection = Constants.Ascending,
            };

            //Act
            var actionResult = _temperatureController.TemperatureHistory(temperatureSearchMl, info,"") as ViewResult;

            //Assert
            Assert.IsNotNull(actionResult, "Temperature action result should not be null");
            Assert.AreEqual(actionResult.ViewName, expectedView, "View name should be TemperatureHistory");
        }
        /// <summary>
        /// Displays the list of inventory 
        /// </summary>
        /// <returns></returns>
        public ActionResult InventoryDetail()
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    InventorySearchModel inventorySearchModel = new InventorySearchModel();
                    IEnumerable<InventoryModel> lstInventoryDetails;
                    List<DeviceModel> devices;
                    using (JetstreamClient objMainServiceClient = new JetstreamClient())
                    {
                        lstInventoryDetails = objMainServiceClient.GetInventoryList(inventorySearchModel.LogicalDeviceId, inventorySearchModel.SearchString);
                        devices = objMainServiceClient.GetDeviceList();
                    }

                    List<SelectListItem> deviceList = new SelectList(devices.OrderBy(x => x.LogicalDeviceId), "LogicalDeviceId", "LogicalDeviceId").ToList();
                    deviceList.Insert(0, new SelectListItem { Text = JetstreamResource.All, Value = string.Empty });
                    ViewBag.DeviceList = deviceList;

                    SortingPagingInfo info = new SortingPagingInfo
                    {
                        SortField = Enums.InventorySortField.Material.ToString(),
                        SortDirection = Constants.Ascending,
                    };
                    lstInventoryDetails = lstInventoryDetails.OrderBy(x => x.Material).Take(Constants.PagingPageSize);
                    ViewBag.SortingPagingInfo = info;

                    if (lstInventoryDetails.Any())
                        inventorySearchModel.InventoryModels = lstInventoryDetails.ToList();

                    return View("InventoryDetail", inventorySearchModel);
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : InventoryDetail() :: InventoryController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : InventoryDetail() :: InventoryController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        /// <summary>
        /// Displays the view
        /// </summary>
        /// <returns></returns>
        public ActionResult Temperature()
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    TemperatureSearchModel temperatureSearchMl = new TemperatureSearchModel();
                    SortingPagingInfo info = new SortingPagingInfo
                    {
                        SortField = Enums.TemperatureSortField.ReadingTime.ToString(),
                        SortDirection = Constants.Ascending,
                    };
                    ShowTemperatureGraph(temperatureSearchMl);
                    temperatureSearchMl.ReadingTimeFrom = DateTime.Now.AddDays(-6).ToShortDateString();
                    temperatureSearchMl.ReadingTimeTo = DateTime.Now.ToShortDateString();

                    if (temperatureSearchMl.TemperatureModels != null)
                        temperatureSearchMl.TemperatureModels = temperatureSearchMl.TemperatureModels.OrderByDescending(x => x.ReadingTime).Take(Constants.PagingPageSize).ToList();
                    ViewBag.SortingPagingInfo = info;
                    return View("TemperatureHistory", temperatureSearchMl);
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : Temperature() :: TemperatureController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : Temperature() :: TemperatureController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        public void InventoryTransaction_OnPost_WithSessionNotNull_ExpectOk()
        {
            //Arrange
            String expectedView = "InventoryTransaction";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(string.Format("{0} {1}", "FName", "LName"));
            _transactionController.ControllerContext = _controllerContext.Object;
            TransactionSearchModel transactionSearchMl = new TransactionSearchModel
            {
                StartDateFrom = "2015-08-04 11:01:17",
                StartDateTo = "2016-02-02 11:01:17"
            };
            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.TransactionSortField.LogicalDeviceId.ToString(),
                SortDirection = Constants.Ascending,
            };

            //Act
            var actionResult = _transactionController.InventoryTransaction(transactionSearchMl, info, "Search") as ViewResult;

            //Assert
            Assert.IsNotNull(actionResult, "Temperature action result should not be null");
            Assert.AreEqual(actionResult.ViewName, expectedView, "View name should be TemperatureHistory");
        }
        public void InventorySearch_OnPost_WithSessionNotNull_ExpectOk()
        {
            //Arrange
            String expectedView = "InventoryDetail";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(string.Format("{0} {1}", "FName", "LName"));
            _inventoryController.ControllerContext = _controllerContext.Object;
            InventorySearchModel inventorySearchModel = new InventorySearchModel
            {
                LogicalDeviceId = "ChetuTestDeviceId",
                SearchString = "test"
            };
            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.InventorySortField.Material.ToString(),
                SortDirection = Constants.Ascending,
            };

            //Act
            var actionResult = _inventoryController.InventoryDetail() as ViewResult;

            //Assert
            Assert.IsNotNull(actionResult, "InventorySearch action result should not be null");
            Assert.AreEqual(actionResult.ViewName, expectedView, "View name should be InventoryDetail");
        }
        /// <summary>
        /// Apply Sorting
        /// </summary>
        /// <param name="info"></param>
        /// <param name="lstUserDetails"></param>
        /// <returns></returns>
        private static IEnumerable<UsersModel> ApplySorting(SortingPagingInfo info, IEnumerable<UsersModel> lstUserDetails)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Enum.IsDefined(typeof(Enums.UserSortField), info.SortField))
                {
                    switch ((Enums.UserSortField)Enum.Parse(typeof(Enums.UserSortField), info.SortField))
                    {
                        case Enums.UserSortField.FirstName:
                            lstUserDetails = info.SortDirection == Constants.Ascending
                                ? lstUserDetails.OrderBy(x => x.FirstName)
                                : lstUserDetails.OrderByDescending(x => x.FirstName);
                            break;
                        case Enums.UserSortField.EmailAddress:
                            lstUserDetails = info.SortDirection == Constants.Ascending
                                ? lstUserDetails.OrderBy(x => x.EmailAddress)
                                : lstUserDetails.OrderByDescending(x => x.EmailAddress);
                            break;
                        case Enums.UserSortField.PassNumber:
                            lstUserDetails = info.SortDirection == Constants.Ascending
                                ? lstUserDetails.OrderBy(x => x.PassNumber)
                                : lstUserDetails.OrderByDescending(x => x.PassNumber);
                            break;
                        case Enums.UserSortField.PassRFID:
                            lstUserDetails = info.SortDirection == Constants.Ascending
                                ? lstUserDetails.OrderBy(x => x.PassRFID)
                                : lstUserDetails.OrderByDescending(x => x.PassRFID);
                            break;
                        case Enums.UserSortField.StatusDescription:
                            lstUserDetails = info.SortDirection == Constants.Ascending
                                ? lstUserDetails.OrderBy(x => x.StatusDescription)
                                : lstUserDetails.OrderByDescending(x => x.StatusDescription);
                            break;
                    }
                }
                return lstUserDetails;
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : ApplySorting(SortingPagingInfo info, IEnumerable<UsersModel> lstUserDetails) :: UserController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return null;
            }
        }
        /// <summary>
        /// Get user detail
        /// </summary>
        /// <returns></returns>
        public ActionResult GetUserDetails()
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    IEnumerable<UsersModel> lstUserDetails;
                    using (JetstreamClient objMainServiceClient = new JetstreamClient())
                    {
                        lstUserDetails = objMainServiceClient.GetFilterUserModelList(string.Empty);
                    }

                    SortingPagingInfo info = new SortingPagingInfo
                    {
                        SortField = Enums.UserSortField.FirstName.ToString(),
                        SortDirection = Constants.Ascending,
                    };

                    lstUserDetails = lstUserDetails.OrderBy(x => x.FirstName).Take(Constants.PagingPageSize);
                    ViewBag.SortingPagingInfo = info;
                    return View("UserDetails", lstUserDetails);
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : GetUserDetails() :: UserController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);
                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : GetUserDetails() :: UserController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        /// <summary>
        /// Method to get the device list with search text
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortField"></param>
        /// <param name="sortDirection"></param>
        /// <returns></returns>
        public JsonResult GetDeviceList(string searchText, int pageIndex, int pageSize, string sortField, string sortDirection)
        {
            List<DeviceModel> deviceModels;
            using (JetstreamClient objMainServiceClient = new JetstreamClient())
            {
                var deviceList = objMainServiceClient.GetFilterDeviceList(searchText);

                SetDeviceLocation(deviceList);

                SortingPagingInfo info = new SortingPagingInfo
                {
                    SortField = sortField,
                    SortDirection = sortDirection,
                };
                deviceModels = ApplySorting(info, deviceList).Skip(pageIndex * pageSize).Take(pageSize).ToList();
            }
            return Json(new { deviceModels }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult EditDevice(DeviceModel deviceMl, string command, SortingPagingInfo info)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null && deviceMl != null)
                {
                    if (string.Equals(command, JetstreamResource.UpdateCommand))
                    {
                        return RedirectToAction("EditCurrentDevice", new { deviceId = deviceMl.DeviceId });
                    }
                    else if (string.Equals(command, JetstreamResource.CancelCommand))
                    {
                        return RedirectToAction("DeviceDetail", "Device");
                    }
                    else if (string.Equals(command, JetstreamResource.DeleteCommand))
                    {
                        return RedirectToAction("DeleteDevice", new { deviceId = deviceMl.DeviceId });
                    }
                    else
                    {
                        using (JetstreamClient objMainServiceClient = new JetstreamClient())
                        {
                            deviceMl = objMainServiceClient.GetDeviceByDeviceId(deviceMl.DeviceId);
                        }

                        deviceMl.Inventories = ApplySortingInventory(info, deviceMl.Inventories).Take(Constants.PagingPageSize).ToList();

                        ViewBag.SortingPagingInfo = info;
                        return View("EditDevice", deviceMl);
                    }
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : EditDevice(DeviceModel deviceMl, string command, SortingPagingInfo info) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : EditDevice(DeviceModel deviceMl, string command, SortingPagingInfo info) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        /// <summary>
        /// return json for server side paging
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortField"></param>
        /// <param name="sortDirection"></param>
        /// <param name="searchString"></param>
        /// <param name="startDateFrom"></param>
        /// <param name="startDateTo"></param>
        /// <returns></returns>
        public JsonResult GetTransactionsList(int pageIndex, int pageSize, string sortField, string sortDirection, string searchString, string startDateFrom, string startDateTo)
        {
            List<TransactionModel> transactionModels;
            using (JetstreamClient objMainServiceClient = new JetstreamClient())
            {
                List<TransactionModel> transactionList;
                transactionList = objMainServiceClient.GetInventoryTransaction(searchString, startDateFrom,
                     startDateTo);

                transactionList.ForEach(x =>
                {
                    x.Location = x.Latitude +
                                 (x.Longitude != null ? string.Format(":{0}", x.Longitude) : x.Longitude)
                                 + (x.Range != null ? string.Format(":{0}", x.Range) : x.Range);
                });

                SortingPagingInfo info = new SortingPagingInfo
                {
                    SortField = sortField,
                    SortDirection = sortDirection,
                };
                transactionModels = ApplySorting(transactionList, info).Skip(pageIndex * pageSize).Take(pageSize).ToList();
            }
            return Json(new { transactionModels }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// Apply sorting on transaction list
        /// </summary>
        /// <param name="lstTransactionModel"></param>
        /// <param name="info"></param>
        private List<TransactionModel> ApplySorting(List<TransactionModel> lstTransactionModel, SortingPagingInfo info)
        {
            if (Enum.IsDefined(typeof(Enums.TransactionSortField), info.SortField))
            {
                switch ((Enums.TransactionSortField)Enum.Parse(typeof(Enums.TransactionSortField), info.SortField))
                {
                    case Enums.TransactionSortField.CurrentState:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderBy(x => x.CurrentState).ToList()
                            : lstTransactionModel.OrderByDescending(x => x.CurrentState).ToList();
                        break;
                    case Enums.TransactionSortField.Material:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderBy(x => x.Material).ToList()
                            : lstTransactionModel.OrderByDescending(x => x.Material).ToList();
                        break;
                    case Enums.TransactionSortField.Batch:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderBy(x => x.Batch).ToList()
                            : lstTransactionModel.OrderByDescending(x => x.Batch).ToList();
                        break;
                    case Enums.TransactionSortField.EPC:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderBy(x => x.EPC).ToList()
                            : lstTransactionModel.OrderByDescending(x => x.EPC).ToList();
                        break;
                    case Enums.TransactionSortField.StateDate:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderByDescending(x => x.StateDate).ToList()
                            : lstTransactionModel.OrderBy(x => x.StateDate).ToList();
                        break;
                    case Enums.TransactionSortField.UserName:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderBy(x => x.UserName).ToList()
                            : lstTransactionModel.OrderByDescending(x => x.UserName).ToList();
                        break;
                    case Enums.TransactionSortField.LogicalDeviceId:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderBy(x => x.LogicalDeviceId).ToList()
                            : lstTransactionModel.OrderByDescending(x => x.LogicalDeviceId).ToList();
                        break;
                    case Enums.TransactionSortField.Location:
                        lstTransactionModel = info.SortDirection == Constants.Ascending
                            ? lstTransactionModel.OrderBy(x => x.Location).ToList()
                            : lstTransactionModel.OrderByDescending(x => x.Location).ToList();
                        break;
                }
            }

            return lstTransactionModel;
        }
        /// <summary>
        /// Method to apply sorting to the temperature list
        /// </summary>
        /// <param name="temperatureModels"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        private List<TemperatureModel> ApplySorting(List<TemperatureModel> temperatureModels, SortingPagingInfo info)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (temperatureModels != null && Enum.IsDefined(typeof(Enums.TemperatureSortField), info.SortField))
                {
                    switch ((Enums.TemperatureSortField)Enum.Parse(typeof(Enums.TemperatureSortField), info.SortField))
                    {
                        case Enums.TemperatureSortField.ReadingTime:
                            temperatureModels = info.SortDirection == Constants.Ascending
                                ? temperatureModels.OrderByDescending(x => x.ReadingTime).ToList()
                                : temperatureModels.OrderBy(x => x.ReadingTime).ToList();
                            break;
                        case Enums.TemperatureSortField.ReadingName:
                            temperatureModels = info.SortDirection == Constants.Ascending
                                ? temperatureModels.OrderBy(x => x.ReadingName).ToList()
                                : temperatureModels.OrderByDescending(x => x.ReadingName).ToList();
                            break;
                        case Enums.TemperatureSortField.ReadingValue:
                            temperatureModels = info.SortDirection == Constants.Ascending
                                ? temperatureModels.OrderBy(x => x.ReadingValue).ToList()
                                : temperatureModels.OrderByDescending(x => x.ReadingValue).ToList();
                            break;
                    }
                }

                return temperatureModels;
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : ApplySorting(List<TemperatureModel> temperatureModels, SortingPagingInfo info) :: TemperatureController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="temperatureSearchMl"></param>
        /// <param name="info"></param>
        private void ReloadGraph(TemperatureSearchModel temperatureSearchMl, SortingPagingInfo info)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                BindDevices();
                //Create the empty highchart which will be shown when the Temperature screen is loaded
                var chart = new Highcharts(JetstreamResource.HighChartName)
                    .InitChart(new Chart { DefaultSeriesType = ChartTypes.Line })
                    .SetTitle(new Title { Text = JetstreamResource.HighChartTitleText, Style = JetstreamResource.HighChartStyle })
                    .SetSubtitle(new Subtitle { Text = "" })
                    .SetXAxis(new XAxis { Categories = null, EndOnTick = true })
                    .SetYAxis(new YAxis { Title = new YAxisTitle { Text = JetstreamResource.HighChartYAxisText, Style = JetstreamResource.HighChartStyle } })
                    .SetTooltip(new Tooltip
                    {
                        Enabled = true,
                        Formatter = @"function() {return '<b>' + this .series.name + '<br/><br/>'+this.x+': '+this.y; }"
                    })
                    .SetPlotOptions(new PlotOptions { Line = new PlotOptionsLine { DataLabels = new PlotOptionsLineDataLabels { Enabled = true }, EnableMouseTracking = false } })
                    .SetSeries(new[] { new Series { Name = JetstreamResource.ProbeA }, new Series { Name = JetstreamResource.ProbeB } });
                ViewData["chart"] = chart;
                ViewBag.SortingPagingInfo = info;
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : ReloadGraph(TemperatureSearchModel temperatureSearchMl, SortingPagingInfo info) :: TemperatureController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());                
            }
        }
        public void DeviceDetail_OnPost_WithSessionIsNull_ExpectUserLogin()
        {
            //Arrange
            String expectedController = "Login";
            String expectedAction = "UserLogin";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(null);
            _deviceController.ControllerContext = _controllerContext.Object;
            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.DeviceSortField.LogicalDeviceId.ToString(),
                SortDirection = Constants.Ascending,
                SearchText = string.Empty
            };

            //Act
            var redirectToRouteResult = _deviceController.DeviceDetail(info) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(redirectToRouteResult, "Not a redirect result");
            Assert.IsFalse(redirectToRouteResult.Permanent); // Or IsTrue if you use RedirectToActionPermanent
            Assert.AreEqual(expectedAction, redirectToRouteResult.RouteValues["Action"]);
            Assert.AreEqual(expectedController, redirectToRouteResult.RouteValues["Controller"]);
        }
        public void DeviceDetail_OnPost_WithSessionNotNull_ExpectOk()
        {
            //Arrange
            String expectedView = "DeviceDetail";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(string.Format("{0} {1}", "FName", "LName"));
            _deviceController.ControllerContext = _controllerContext.Object;
            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.DeviceSortField.LogicalDeviceId.ToString(),
                SortDirection = Constants.Ascending,
                SearchText = string.Empty
            };

            //Act
            var actionResult = _deviceController.DeviceDetail(info) as ViewResult;

            //Assert
            Assert.IsNotNull(actionResult, "DeviceDetail action result should not be null");
            Assert.AreEqual(actionResult.ViewName, expectedView, "View name should be DeviceDetail");
        }
        /// <summary>
        /// Search Items for server side paging and searching
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortField"></param>
        /// <param name="sortDirection"></param>
        /// <returns></returns>
        public JsonResult GetItemsList(string searchText, int pageIndex, int pageSize, string sortField, string sortDirection)
        {
            List<ItemModel> itemsModel;
            using (JetstreamClient objMainServiceClient = new JetstreamClient())
            {
                var itemList = objMainServiceClient.GetFilterItemList(searchText);

                SortingPagingInfo info = new SortingPagingInfo
                {
                    SortField = sortField,
                    SortDirection = sortDirection,
                };
                itemsModel = ApplySorting(info, itemList).Skip(pageIndex * pageSize).Take(pageSize).ToList();

            }
            return Json(new { itemsModel }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult InventoryTransaction(TransactionSearchModel transactionSearchMl, SortingPagingInfo info, string command)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && !CheckDate(transactionSearchMl.StartDateFrom))
                    {
                        transactionSearchMl.TransactionModels = null;
                        Warning(JetstreamResource.FromDateValidation, true);
                        ViewBag.SortingPagingInfo = info;
                        return View("InventoryTransaction", transactionSearchMl);
                    }

                    if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && !CheckDate(transactionSearchMl.StartDateTo))
                    {
                        transactionSearchMl.TransactionModels = null;
                        Warning(JetstreamResource.ToDateValidation, true);
                        ViewBag.SortingPagingInfo = info;
                        return View("InventoryTransaction", transactionSearchMl);
                    }

                    DateTime? StartDateFrom = !string.IsNullOrEmpty(transactionSearchMl.StartDateFrom) ? Convert.ToDateTime(transactionSearchMl.StartDateFrom) : (DateTime?)null;
                    DateTime? StartDateTo = !string.IsNullOrEmpty(transactionSearchMl.StartDateTo) ? Convert.ToDateTime(transactionSearchMl.StartDateTo) : (DateTime?)null;

                    if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && StartDateFrom > StartDateTo)
                    {
                        transactionSearchMl.TransactionModels = null;
                        Warning(JetstreamResource.DateValidation, true);
                        ViewBag.SortingPagingInfo = info;
                        return View("InventoryTransaction", transactionSearchMl);
                    }

                    using (JetstreamClient objMainServiceClient = new JetstreamClient())
                    {
                        IEnumerable<TransactionModel> lstTransactionModel;
                        lstTransactionModel =
                            objMainServiceClient.GetInventoryTransaction(transactionSearchMl.SearchString,
                                transactionSearchMl.StartDateFrom, transactionSearchMl.StartDateTo);

                        lstTransactionModel.ToList().ForEach(x =>
                        {
                            x.Location = x.Latitude + (x.Longitude != null ? string.Format(":{0}", x.Longitude) : x.Longitude)
                                + (x.Range != null ? string.Format(":{0}", x.Range) : x.Range);
                        });
                        if (lstTransactionModel.Any())
                        {
                            transactionSearchMl.TransactionModels = ApplySorting(lstTransactionModel.ToList(), info).Take(Constants.PagingPageSize).ToList();
                        }
                    }
                    ViewBag.SortingPagingInfo = info;
                    return View("InventoryTransaction", transactionSearchMl);

                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : InventoryTransaction(TransactionSearchModel transactionSearchMl, SortingPagingInfo info, string command) :: TransactionController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : InventoryTransaction(TransactionSearchModel transactionSearchMl, SortingPagingInfo info, string command) :: TransactionController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
 /// <summary>
 /// Apply sorting to inventory list
 /// </summary>
 /// <param name="info"></param>
 /// <param name="lstInventoryDetails"></param>
 /// <returns></returns>
 private static IEnumerable<InventoryModel> ApplySorting(SortingPagingInfo info, IEnumerable<InventoryModel> lstInventoryDetails)
 {
     if (Enum.IsDefined(typeof(Enums.InventorySortField), info.SortField))
     {
         switch ((Enums.InventorySortField)Enum.Parse(typeof(Enums.InventorySortField), info.SortField))
         {
             case Enums.InventorySortField.Material:
                 lstInventoryDetails = info.SortDirection == Constants.Ascending
                     ? lstInventoryDetails.OrderBy(x => x.Material)
                     : lstInventoryDetails.OrderByDescending(x => x.Material);
                 break;
             case Enums.InventorySortField.Batch:
                 lstInventoryDetails = info.SortDirection == Constants.Ascending
                     ? lstInventoryDetails.OrderBy(x => x.Batch)
                     : lstInventoryDetails.OrderByDescending(x => x.Batch);
                 break;
             case Enums.InventorySortField.TagEPC:
                 lstInventoryDetails = info.SortDirection == Constants.Ascending
                     ? lstInventoryDetails.OrderBy(x => x.TagEPC)
                     : lstInventoryDetails.OrderByDescending(x => x.TagEPC);
                 break;
             case Enums.InventorySortField.ExpirationDate:
                 lstInventoryDetails = info.SortDirection == Constants.Ascending
                     ? lstInventoryDetails.OrderByDescending(x => x.ExpirationDate)
                     : lstInventoryDetails.OrderBy(x => x.ExpirationDate);
                 break;
             case Enums.InventorySortField.Device:
                 lstInventoryDetails = info.SortDirection == Constants.Ascending
                     ? lstInventoryDetails.OrderBy(x => x.Device)
                     : lstInventoryDetails.OrderByDescending(x => x.Device);
                 break;
         }
     }
     return lstInventoryDetails;
 }
 /// <summary>
 /// Method to get the Inventory list by page number and page size for server side paging
 /// </summary>
 /// <param name="logicalDeviceId"></param>
 /// <param name="searchText"></param>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <param name="sortField"></param>
 /// <param name="sortDirection"></param>
 /// <returns></returns>
 public JsonResult GetInventoryList(string logicalDeviceId, string SearchString, int pageIndex, int pageSize, string sortField, string sortDirection)
 {
     List<InventoryModel> inventoriesModel;
     using (JetstreamClient objMainServiceClient = new JetstreamClient())
     {
         var inventoryList = objMainServiceClient.GetInventoryList(logicalDeviceId, SearchString);
         SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = sortField,
                SortDirection = sortDirection,
            };
         inventoriesModel = ApplySorting(info, inventoryList).Skip(pageIndex * pageSize).Take(pageSize).ToList();
     }
     return Json(new { inventoriesModel }, JsonRequestBehavior.AllowGet);
 }
        public void TemperatureHistory_WithSessionIsNull_ExpectUserLogin()
        {
            //Arrange
            String expectedController = "Login";
            String expectedAction = "UserLogin";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(null);
            _temperatureController.ControllerContext = _controllerContext.Object;
            TemperatureSearchModel temperatureSearchMl = new TemperatureSearchModel
            {
                DeviceId = 21,
                LogicalDeviceId = "ChetuTestDeviceId",
                ReadingTimeFrom = "2015-08-04 11:01:17",
                ReadingTimeTo = "2016-02-02 11:01:17"
            };
            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.TemperatureSortField.ReadingTime.ToString(),
                SortDirection = Constants.Ascending,
            };

            //Act
            var redirectToRouteResult = _temperatureController.TemperatureHistory(temperatureSearchMl, info,"") as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(redirectToRouteResult, "Not a redirect result");
            Assert.IsFalse(redirectToRouteResult.Permanent); // Or IsTrue if you use RedirectToActionPermanent
            Assert.AreEqual(expectedAction, redirectToRouteResult.RouteValues["Action"]);
            Assert.AreEqual(expectedController, redirectToRouteResult.RouteValues["Controller"]);
        }
        public ActionResult DeviceDetail(SortingPagingInfo info)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    IEnumerable<DeviceModel> lstDeviceDetail;
                    using (JetstreamClient objMainServiceClient = new JetstreamClient())
                    {
                        lstDeviceDetail = objMainServiceClient.GetFilterDeviceList(info.SearchText);
                    }
                    SetDeviceLocation(lstDeviceDetail);

                    lstDeviceDetail = ApplySorting(info, lstDeviceDetail).Take(Constants.PagingPageSize);

                    ViewBag.SortingPagingInfo = info;
                    ViewBag.SortField = info.SortField;
                    return View("DeviceDetail", lstDeviceDetail);
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : DeviceDetail(SortingPagingInfo info) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : DeviceDetail(SortingPagingInfo info) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        /// <summary>
        /// Displays the view
        /// </summary>
        /// <returns></returns>
        public ActionResult InventoryTransaction()
        {
            StringBuilder objStringBuilderError = new StringBuilder();

            TransactionSearchModel transactionSearchMl = new TransactionSearchModel();
            try
            {
                if (Session["UserName"] != null)
                {
                    using (JetstreamClient objMainServiceClient = new JetstreamClient())
                    {
                        IEnumerable<TransactionModel> lstTransactionModel = objMainServiceClient.GetInventoryTransaction(transactionSearchMl.SearchString, transactionSearchMl.StartDateFrom, transactionSearchMl.StartDateTo);

                        lstTransactionModel.ToList().ForEach(x =>
                        {
                            x.Location = x.Latitude +
                                         (x.Longitude != null ? string.Format(":{0}", x.Longitude) : x.Longitude)
                                         + (x.Range != null ? string.Format(":{0}", x.Range) : x.Range);
                        });

                        if (lstTransactionModel.Any())
                        {
                            transactionSearchMl.TransactionModels = new List<TransactionModel>(lstTransactionModel);
                        }
                    }

                    SortingPagingInfo info = new SortingPagingInfo
                    {
                        SortField = Enums.TransactionSortField.StateDate.ToString(),
                        SortDirection = Constants.Ascending,
                    };
                    if (transactionSearchMl.TransactionModels != null)
                        transactionSearchMl.TransactionModels = ApplySorting(transactionSearchMl.TransactionModels, info).Take(Constants.PagingPageSize).ToList();
                    ViewBag.SortingPagingInfo = info;

                    transactionSearchMl.StartDateFrom = string.Empty;// DateTime.Now.ToShortDateString();
                    transactionSearchMl.StartDateTo = string.Empty; //DateTime.Now.ToShortDateString();
                    return View("InventoryTransaction", transactionSearchMl);
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : InventoryTransaction() :: TransactionController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : InventoryTransaction() :: TransactionController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
 /// <summary>
 /// Applying sorting to device inventory list
 /// </summary>
 /// <param name="info"></param>
 /// <param name="inventoryMl"></param>
 /// <returns></returns>
 private static IEnumerable<InventoryModel> ApplySortingInventory(SortingPagingInfo info, IEnumerable<InventoryModel> inventoryMl)
 {
     if (Enum.IsDefined(typeof(Enums.InventorySortField), info.SortField))
     {
         switch ((Enums.InventorySortField)Enum.Parse(typeof(Enums.InventorySortField), info.SortField))
         {
             case Enums.InventorySortField.Material:
                 inventoryMl = info.SortDirection == Constants.Ascending
                     ? inventoryMl.OrderBy(x => x.Material)
                     : inventoryMl.OrderByDescending(x => x.Material);
                 break;
             case Enums.InventorySortField.Batch:
                 inventoryMl = info.SortDirection == Constants.Ascending
                     ? inventoryMl.OrderBy(x => x.Batch)
                     : inventoryMl.OrderByDescending(x => x.Batch);
                 break;
             case Enums.InventorySortField.ExpirationDate:
                 inventoryMl = info.SortDirection == Constants.Ascending
                     ? inventoryMl.OrderBy(x => x.ExpirationDate)
                     : inventoryMl.OrderByDescending(x => x.ExpirationDate);
                 break;
             case Enums.InventorySortField.TagEPC:
                 inventoryMl = info.SortDirection == Constants.Ascending
                     ? inventoryMl.OrderBy(x => x.TagEPC)
                     : inventoryMl.OrderByDescending(x => x.TagEPC);
                 break;
         }
     }
     return inventoryMl;
 }
 /// <summary>
 /// Get the json result for server side paging
 /// </summary>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <param name="logicalDeviceId"></param>
 /// <param name="readingTimeFrom"></param>
 /// <param name="readingTimeTo"></param>
 /// <param name="sortField"></param>
 /// <param name="sortDirection"></param>
 /// <returns></returns>
 public JsonResult GetTemperaturesList(int pageIndex, int pageSize, string logicalDeviceId, string readingTimeFrom, string readingTimeTo, string sortField, string sortDirection)
 {
     SortingPagingInfo info = new SortingPagingInfo
         {
             SortField = sortField,
             SortDirection = sortDirection,
         };
     List<TemperatureModel> lstTemperatureModel = TempData["TemperatureModels"] as List<TemperatureModel>;
     var temperatureModels = TempData["TemperatureModels"] != null ? ApplySorting(TempData["TemperatureModels"] as List<TemperatureModel>, info).Skip(pageIndex * pageSize).Take(pageSize).ToList() : null;
     TempData["TemperatureModels"] = lstTemperatureModel;
     return Json(new { temperatureModels }, JsonRequestBehavior.AllowGet);
 }
        /// <summary>
        /// Applying sorting to device list
        /// </summary>
        /// <param name="info"></param>
        /// <param name="lstDeviceDetail"></param>
        /// <returns></returns>
        private static IEnumerable<DeviceModel> ApplySorting(SortingPagingInfo info, IEnumerable<DeviceModel> lstDeviceDetail)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Enum.IsDefined(typeof(Enums.DeviceSortField), info.SortField))
                {
                    switch ((Enums.DeviceSortField)Enum.Parse(typeof(Enums.DeviceSortField), info.SortField))
                    {
                        case Enums.DeviceSortField.LogicalDeviceId:
                            lstDeviceDetail = info.SortDirection == Constants.Ascending
                                ? lstDeviceDetail.OrderBy(x => x.LogicalDeviceId)
                                : lstDeviceDetail.OrderByDescending(x => x.LogicalDeviceId);
                            break;
                        case Enums.DeviceSortField.SerialNumber:
                            lstDeviceDetail = info.SortDirection == Constants.Ascending
                                ? lstDeviceDetail.OrderBy(x => x.SerialNumber)
                                : lstDeviceDetail.OrderByDescending(x => x.SerialNumber);
                            break;
                        case Enums.DeviceSortField.TotalInventory:
                            lstDeviceDetail = info.SortDirection == Constants.Ascending
                                ? lstDeviceDetail.OrderBy(x => x.TotalInventory)
                                : lstDeviceDetail.OrderByDescending(x => x.TotalInventory);
                            break;
                        case Enums.DeviceSortField.Temperature:
                            lstDeviceDetail = info.SortDirection == Constants.Ascending
                                ? lstDeviceDetail.OrderBy(x => x.Temperature)
                                : lstDeviceDetail.OrderByDescending(x => x.Temperature);
                            break;
                        case Enums.DeviceSortField.Location:
                            lstDeviceDetail = info.SortDirection == Constants.Ascending
                                ? lstDeviceDetail.OrderBy(x => x.Location)
                                : lstDeviceDetail.OrderByDescending(x => x.Location);
                            break;
                        case Enums.DeviceSortField.LastUpdate:
                            lstDeviceDetail = info.SortDirection == Constants.Ascending
                                ? lstDeviceDetail.OrderByDescending(x => x.LastUpdate)
                                : lstDeviceDetail.OrderBy(x => x.LastUpdate);
                            break;
                    }
                }
                return lstDeviceDetail;
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : ApplySorting(SortingPagingInfo info, IEnumerable<DeviceModel> lstDeviceDetail) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return null;
            }
        }
        /// <summary>
        /// Search the temperature history by date and model
        /// </summary>
        /// <param name="temperatureSearchMl"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public ActionResult TemperatureHistory(TemperatureSearchModel temperatureSearchMl, SortingPagingInfo info, string command)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && !CheckDate(temperatureSearchMl.ReadingTimeFrom))
                    {
                        temperatureSearchMl.TemperatureModels = null;
                        ReloadGraph(temperatureSearchMl, info);
                        Warning(JetstreamResource.FromDateValidation, true);
                        return View("TemperatureHistory", temperatureSearchMl);
                    }

                    if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && !CheckDate(temperatureSearchMl.ReadingTimeTo))
                    {
                        temperatureSearchMl.TemperatureModels = null;
                        ReloadGraph(temperatureSearchMl, info);
                        Warning(JetstreamResource.ToDateValidation, true);
                        return View("TemperatureHistory", temperatureSearchMl);
                    }

                    DateTime? fromReadingTime = !string.IsNullOrEmpty(temperatureSearchMl.ReadingTimeFrom) ? Convert.ToDateTime(temperatureSearchMl.ReadingTimeFrom) : (DateTime?)null;
                    DateTime? toReadingTime = !string.IsNullOrEmpty(temperatureSearchMl.ReadingTimeTo) ? Convert.ToDateTime(temperatureSearchMl.ReadingTimeTo) : (DateTime?)null;

                    if (!string.IsNullOrEmpty(command) && command.Equals(JetstreamResource.SearchCommand) && fromReadingTime > toReadingTime)
                    {
                        temperatureSearchMl.TemperatureModels = null;
                        ReloadGraph(temperatureSearchMl, info);
                        Warning(JetstreamResource.DateValidation, true);
                        return View("TemperatureHistory", temperatureSearchMl);
                    }

                    ShowTemperatureGraph(temperatureSearchMl);
                    if (temperatureSearchMl.TemperatureModels != null)
                    {
                        temperatureSearchMl.TemperatureModels =
                            ApplySorting(temperatureSearchMl.TemperatureModels, info)
                                .Take(Constants.PagingPageSize)
                                .ToList();
                    }
                    ViewBag.SortingPagingInfo = info;
                    return View("TemperatureHistory", temperatureSearchMl);
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : TemperatureHistory(TemperatureSearchModel temperatureSearchMl, SortingPagingInfo info, string command) :: TemperatureController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : TemperatureHistory(TemperatureSearchModel temperatureSearchMl, SortingPagingInfo info, string command) :: TemperatureController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        /// <summary>
        /// Displays view to edit device
        /// </summary>
        /// <param name="logicalDeviceId"></param>
        /// <returns></returns>
        public ActionResult GetDevice(string logicalDeviceId)
        {
            StringBuilder objStringBuilderError = new StringBuilder();
            try
            {
                if (Session["UserName"] != null)
                {
                    DeviceModel deviceMl;
                    using (JetstreamClient objMainServiceClient = new JetstreamClient())
                    {
                        deviceMl = objMainServiceClient.GetDeviceByLogicalDeviceId(logicalDeviceId);
                    }
                    SortingPagingInfo info = new SortingPagingInfo
                    {
                        SortField = Enums.InventorySortField.Material.ToString(),
                        SortDirection = Constants.Ascending,
                        SearchText = string.Empty
                    };
                    if (deviceMl != null)
                        deviceMl.Inventories = deviceMl.Inventories.OrderBy(x => x.Material).Take(Constants.PagingPageSize).ToList();
                    ViewBag.SortingPagingInfo = info;
                    return View("EditDevice", deviceMl);
                }
                else
                {
                    return RedirectToAction("UserLogin", "Login");
                }
            }
            catch (FaultException<ServiceData> fex)
            {
                objStringBuilderError.AppendLine("In method : GetDevice(string logicalDeviceId) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
            catch (Exception ex)
            {
                objStringBuilderError.AppendLine("In method : GetDevice(string logicalDeviceId) :: DeviceController");
                objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
                objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());

                SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
                return View("Error");
            }
        }
        public void GetUserDetails_WithSessionNotNullAndSortingPagingInfo_ExpectOk()
        {
            //Arrange
            String expectedView = "UserDetails";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(string.Format("{0} {1}", "FName", "LName"));
            _userController.ControllerContext = _controllerContext.Object;

            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.UserSortField.EmailAddress.ToString(),
                SortDirection = Constants.Ascending,
                SearchText = "Fname"
            };

            //Act
            var actionResult = _userController.GetUserDetails(info) as ViewResult;

            //Assert
            Assert.IsNotNull(actionResult, "AddUserDetails action result should not be null");
            Assert.AreEqual(actionResult.ViewName, expectedView, "View name should be AddUser");
        }
        /// <summary>
        ///  Method to get the inventory lists
        /// </summary>
        /// <param name="logicalDeviceId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortField"></param>
        /// <param name="sortDirection"></param>
        /// <returns></returns>
        public JsonResult GetDeviceInventoriesList(string logicalDeviceId, int pageIndex, int pageSize, string sortField, string sortDirection)
        {
            DeviceModel deviceModel;
            using (JetstreamClient objMainServiceClient = new JetstreamClient())
            {
                deviceModel = objMainServiceClient.GetDeviceInventoriesList(logicalDeviceId);

                SortingPagingInfo info = new SortingPagingInfo
                {
                    SortField = sortField,
                    SortDirection = sortDirection,
                };
                deviceModel.Inventories = ApplySortingInventory(info, deviceModel.Inventories).Skip(pageIndex * pageSize).Take(pageSize).ToList();
            }
            return Json(new { deviceModel }, JsonRequestBehavior.AllowGet);
        }
        public void GetUserDetails_WithSessionIsNullAndSortingPagingInfo_ExpectUserLogin()
        {
            //Arrange
            String expectedController = "Login";
            String expectedAction = "UserLogin";
            _controllerContext.Setup(cc => cc.HttpContext.Session["UserName"]).Returns(null);
            _userController.ControllerContext = _controllerContext.Object;

            SortingPagingInfo info = new SortingPagingInfo
            {
                SortField = Enums.UserSortField.FirstName.ToString(),
                SortDirection = Constants.Ascending,
            };

            //Act
            var redirectToRouteResult = _userController.GetUserDetails(info) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(redirectToRouteResult, "Not a redirect result");
            Assert.IsFalse(redirectToRouteResult.Permanent); // Or IsTrue if you use RedirectToActionPermanent
            Assert.AreEqual(expectedAction, redirectToRouteResult.RouteValues["Action"]);
            Assert.AreEqual(expectedController, redirectToRouteResult.RouteValues["Controller"]);
        }