Esempio n. 1
0
        public static AppStatsObj LoadDashboard(AppStatSearchObj regObj, string username)
        {
            var response = new AppStatsObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.LOAD_DASHBOARD_STATS_ENDPOINT, username, Method.POST).ProcessAPI <AppStatSearchObj, AppStatsObj>(regObj, out var msg);
                if (msg.Code == 0 && string.IsNullOrEmpty(msg.TechMessage) && string.IsNullOrEmpty(msg.Message))
                {
                    return(apiResponse);
                }

                response.Status.Message.FriendlyMessage  = msg.Message;
                response.Status.Message.TechnicalMessage = msg.TechMessage;
                return(response);
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                return(response);
            }
        }
Esempio n. 2
0
        public ActionResult Index(int?ClientId, int?ProductId, int?ProductItemId)
        {
            try
            {
                #region Curent user session check

                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    return(RedirectToActionPermanent("Login", "Portal"));
                }

                #endregion

                #region check if productitemid is 0, initialize  productItemId from ProductItemService based on client and product

                if (ProductItemId == 0)
                {
                    var searchObjForItem = new ProductItemSearchObj
                    {
                        AdminUserId = userData.UserId,
                        ClientId    = ClientId ?? 0,
                        ProductId   = ProductId ?? 0,
                        Status      = -2,
                    };
                    var retValForItem = ProductItemService.LoadProductItems(searchObjForItem, userData.Username);
                    var items         = retValForItem.ProductItems.Where(m => m.ProductId == ProductId && m.ClientId == ClientId).ToList();

                    var itemCount = items.Count(m => m.ClientId == ClientId && m.ProductId == ProductId);

                    ViewBag.productItemCount = itemCount;
                    if (itemCount == 1)
                    {
                        var itemId = Convert.ToInt32(items.FirstOrDefault(m => m.ProductId == ProductId && m.ClientId == ClientId).ProductItemId);
                        ViewBag.productItemId = itemId;
                        ProductItemId         = itemId;
                    }
                }


                #endregion

                #region client, product and item session initialization
                AppSession newSession        = null;
                var        userClientSession = (AppSession)Session["_UserClientSession_"];

                newSession = new AppSession
                {
                    ClientId      = ClientId ?? 0,
                    ProductId     = ProductId ?? 0,
                    ProductItemId = ProductItemId ?? 0,
                };
                Session["_UserClientSession_"] = newSession;

                var clientId      = ClientId ?? newSession.ClientId;
                var productId     = ProductId ?? newSession.ProductId;
                var productItemId = ProductItemId ?? newSession.ProductItemId;

                #endregion


                var obj = new ClientProductInfoObj {
                    CurrentClientId = clientId, CurrentProductId = productId, CurrentProductItemId = productItemId, ProductInfo = new ProductItemObj()
                };

                if (clientId > 0 && productId > 0)
                {
                    var prodInfo = getProductItemObj(clientId, productId, productItemId);
                    if (prodInfo.ProductItemId > 0)
                    {
                        obj.ProductInfo = prodInfo;
                    }
                }

                var searchObj = new AppStatSearchObj
                {
                    AdminUserId   = userData.UserId,
                    StartDate     = "",
                    StopDate      = "",
                    ProductItemId = productItemId,
                    ProductId     = productId,
                    ClientId      = clientId,
                    UserId        = userData.UserId,
                };

                var retVal = DashboardServices.LoadDashboard(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    ViewBag.Error = "No record found!";
                    return(View(new ClientProductInfoObj()));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    ViewBag.Error = "No record found!";
                    return(View(new ClientProductInfoObj()));
                }

                obj.Appstats = retVal;

                if (obj == null)
                {
                    return(View(new ClientProductInfoObj()));
                }
                return(View(obj));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new ClientProductInfoObj()));
            }
        }