public Models.OutletModel GetOutlet(int outletId) { Models.OutletModel response; try { Outlet outlet = _outletManagerRepo.Get(outletId); response = new Models.OutletModel { OutletId = outlet.OutletId, OutletName = outlet.OutletName, OutletAddresss = outlet.OutletAddresss, UserId = outlet.UserId }; } catch (Exception ex) { _outletManagerRepo.Rollback(); int pk; if (_crashLogRepo.AsQueryable().Any()) { pk = 0; } else { pk = _crashLogRepo.AsQueryable().Max(x => x.CrashLogId) + 1; } if (ex.InnerException != null) { _crashLogRepo.Add(new Crashlog { CrashLogId = pk, ClassName = "OutletManagerService", MethodName = "GetOutlet", ErrorMessage = ex.Message, ErrorInner = (string.IsNullOrEmpty(ex.Message) || ex.Message == CommonConstants.MsgInInnerException ? ex.InnerException.Message : ex.Message), Data = outletId.ToString(NumberFormatInfo.CurrentInfo), TimeStamp = DateTime.Now }); } response = null; } return(response); }
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); }