Example #1
0
        public bool AddProductUnitTypes(ProductUnitTypeModel productUnitType)
        {
            int pk;

            try
            {
                if (!_productUnitTypeRepo.AsQueryable().Any())
                {
                    pk = 0;
                }
                else
                {
                    pk = _productUnitTypeRepo.GetMaxPK("UnitTypeIds");
                }

                _productUnitTypeRepo.Add(new ProductUnitType
                {
                    UnitTypeIds   = pk + 1,
                    UnitTypeNames = productUnitType.UnitTypeName,
                    Status        = CommonConstants.StatusTypes.Active
                });

                return(true);
            }
            catch (Exception ex)
            {
                _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
                {
                    CrashLogId   = pk,
                    ClassName    = "ProductService",
                    MethodName   = "AddProductUnitTypes",
                    ErrorMessage = ex.Message,
                    ErrorInner   = msg,
                    Data         = JsonSerializer.Serialize(productUnitType),
                    TimeStamp    = DateTime.Now
                });

                return(false);
            }
        }
Example #2
0
        public int[] SaveProductImages(string[] FileNames, int productId)
        {
            int pk;

            int[] result = new int[FileNames.Length];
            try
            {
                if (_fileRepo.AsQueryable().Any())
                {
                    pk = _fileRepo.AsQueryable().Max(x => x.FileId) + 1;
                }
                else
                {
                    pk = 1;
                }

                int productPicPk = 0;
                if (_productPictureRepo.AsQueryable().Any())
                {
                    productPicPk = _productPictureRepo.AsQueryable().Max(x => x.ProductPictureId) + 1;
                }
                else
                {
                    productPicPk = 1;
                }

                for (int i = 0; i < FileNames.Length; i++)
                {
                    var file = new DataLayer.Entities.File
                    {
                        FileName = FileNames[i],
                        FilePath = Path.Combine("Images", FileNames[i])
                    };
                    _fileRepo.Add(file);


                    _productPictureRepo.Add(new ProductPicture
                    {
                        FileId    = file.FileId,
                        ProductId = productId
                    });

                    result[i] = i + pk;
                }
                return(result);
            }
            catch (Exception ex)
            {
                _fileRepo.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    = "FileService",
                    MethodName   = "SaveFiles",
                    ErrorMessage = ex.Message,
                    ErrorInner   = msg,
                    Data         = JsonSerializer.Serialize("Failed to save file"),
                    TimeStamp    = DateTime.Now
                });
                return(null);
            }
        }