Beispiel #1
0
        public bool?ArchiveProduct(string userId, int productId)
        {
            try
            {
                // Check if product exists
                Product Product = _productRepo.Get(productId);
                if (Product == null)
                {
                    return(false);
                }

                // Veridy user's product
                string prductOwnerId = _outletManagerRepo.Get(_categoryRepo.AsQueryable().FirstOrDefault(x => x.CategoryId == _productRepo.Get(productId).CategoryId).OutletId).UserId;
                if (prductOwnerId != userId)
                {
                    return(false);
                }

                // Archive the product
                Product.Status = CommonConstants.StatusTypes.Archived;
                _productRepo.Update(Product);
                return(true);
            }
            catch (Exception ex)
            {
                int pk;
                _productRepo.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
                {
                    CrashLogId   = pk,
                    ClassName    = "ProductService",
                    MethodName   = "ArchiveProduct",
                    ErrorMessage = ex.Message,
                    ErrorInner   = msg,
                    Data         = JsonSerializer.Serialize("string userId = " + userId + ", int? productId = " + productId),
                    TimeStamp    = DateTime.Now
                });

                return(null);
            }
        }
        public List <CategoryModel> GetCategoriesByOutlets(int OutletId)
        {
            try
            {
                List <CategoryModel> response = new List <CategoryModel>();
                response = _categoryRepo.AsQueryable().Where(x => x.OutletId == OutletId && x.Status == CommonConstants.StatusTypes.Active)
                           .Select(x => new CategoryModel
                {
                    CategoryId       = x.CategoryId,
                    CategoryName     = x.CategoryName,
                    outletId         = x.OutletId,
                    ParentCategoryId = x.ParentCategoryId,
                    UserId           = x.Outlet.UserId
                }).OrderBy(x => x.ParentCategoryId).ToList();

                return(response);
            }
            catch (Exception ex)
            {
                _categoryRepo.Rollback();

                int pk = _crashLogRepo.AsQueryable().Count() + 1;

                _crashLogRepo.Add(new DataLayer.Entities.Crashlog
                {
                    CrashLogId   = pk,
                    ClassName    = "CategoryService",
                    MethodName   = "GetCategoriesByOutlets",
                    ErrorMessage = ex.Message.ToString(),
                    ErrorInner   = (string.IsNullOrEmpty(ex.Message) || ex.Message == CommonConstants.MsgInInnerException ? ex.InnerException.Message : ex.Message).ToString(),
                    Data         = "",
                    TimeStamp    = DateTime.Now
                });

                return(null);
            }
        }