Exemplo n.º 1
0
        public List <Models.OutletModel> AddOutlet(Models.OutletModel outlet)
        {
            List <Models.OutletModel> response = new List <Models.OutletModel>();

            try
            {
                bool status = _outletManagerRepo.Add(new Outlet
                {
                    OutletAddresss = outlet.OutletAddresss,
                    OutletName     = outlet.OutletName,
                    UserId         = outlet.UserId,
                    Status         = CommonConstants.StatusTypes.Active
                });

                if (status)
                {
                    response = _outletManagerRepo.AsQueryable().Where(x => x.UserId == outlet.UserId && x.Status == CommonConstants.StatusTypes.Active).Select(x => new Models.OutletModel {
                        OutletId = x.OutletId, OutletName = x.OutletName
                    }).ToList();
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                _outletManagerRepo.Rollback();

                if (ex.InnerException != null)
                {
                    _crashLogRepo.Add(new Crashlog
                    {
                        ClassName    = "OutletManagerService",
                        MethodName   = "AddOutlet",
                        ErrorMessage = ex.Message,
                        ErrorInner   =
                            (string.IsNullOrEmpty(ex.Message) || ex.Message == CommonConstants.MsgInInnerException
                                ? ex.InnerException.Message
                                : ex.Message),
                        Data      = outlet.UserId,
                        TimeStamp = DateTime.Now
                    });
                }
            }

            return(response);
        }
Exemplo n.º 2
0
        public IEnumerable <ProductModel> GetInventory(OutletModel outletModel)
        {
            IEnumerable <ProductModel> response = new List <ProductModel>();

            try
            {
                List <int> outlets = new List <int>();
                // Return all outlets when no outlet selected
                if (outletModel.OutletId <= 0)
                {
                    // Get Outlet Ids of Person
                    outlets.AddRange(_outletManagerRepo.AsQueryable()
                                     .Where(x => x.UserId == outletModel.UserId && x.Status == CommonConstants.StatusTypes.Active)
                                     .Select(x => x.OutletId)
                                     .ToList());
                }
                else
                {
                    // Check if the person owns the outlet or not
                    Outlet outlet = _outletManagerRepo.Get(outletModel.OutletId);
                    if (outlet == null || outlet.UserId != outletModel.UserId)
                    {
                        return(null);
                    }

                    outlets.Add((int)outletModel.OutletId);
                }


                return(_productRepo.AsQueryable()
                       .Where(product => outlets.Contains(product.Category.OutletId) && product.Status == CommonConstants.StatusTypes.Active)
                       .Select(product => new ProductModel
                {
                    ProductId = product.ProductId,
                    ProductName = product.ProductName,
                    Quantity = product.Quantity,
                    RetailPrice = (int)product.RetailPrice,
                    OutletName = product.Category.Outlet.OutletName
                })
                       .Skip(outletModel.Skip)
                       .Take(outletModel.PageSize)
                       .ToList());
            }
            catch (Exception ex)
            {
                int pk;
                _productUnitTypeRepo.Rollback();

                if (!_crashLogRepo.AsQueryable().Any())
                {
                    pk = 0;
                }
                else
                {
                    pk = _crashLogRepo.GetMaxPK("CrashLogId") + 1;
                }

                string msg = (string.IsNullOrEmpty(ex.Message) || ex.Message.ToLower().Contains(CommonConstants.MsgInInnerException.ToLower()))
                            ? ex.InnerException.Message
                            : ex.Message;
                _crashLogRepo.Add(new Crashlog
                {
                    ClassName    = "ProductService",
                    MethodName   = "SellProduct",
                    ErrorMessage = ex.Message,
                    ErrorInner   = msg,
                    Data         = JsonSerializer.Serialize("string userId = " + outletModel.UserId + ", int? outletId = " + outletModel.OutletId),
                    TimeStamp    = DateTime.Now
                });
                return(null);
            }

            return(response);
        }