コード例 #1
0
        public bool DeleteCategory(int OutletId)
        {
            try
            {
                DataLayer.Entities.Category category = _categoryRepo.Get(OutletId);
                category.Status = CommonConstants.StatusTypes.Archived;
                _categoryRepo.Update(category);

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

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

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

                return(false);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: UserService.cs プロジェクト: nafis-sadik/OrcusUMS
        public bool?SignUp(UserModel user, out string token, out string userId)
        {
            token  = "";
            userId = "";
            User existingUser = _userRepo.AsQueryable().FirstOrDefault(x => x.UserName == user.UserName);

            if (existingUser != null)
            {
                token = CommonConstants.HttpResponseMessages.UserNameExists;
                return(null);
            }

            EmailAddress email = _emailIdRepo.AsQueryable().FirstOrDefault(x => Convert.ToString(x.EmailAddress1) == user.DefaultEmail);

            if (email != null)
            {
                token = CommonConstants.HttpResponseMessages.MailExists;
                return(null);
            }

            try
            {
                userId = Guid.NewGuid().ToString();

                _userRepo.Add(new User
                {
                    UserId         = userId,
                    FirstName      = user.FirstName,
                    MiddleName     = user.MiddleName,
                    LastName       = user.LastName,
                    Status         = CommonConstants.StatusTypes.Active,
                    Password       = BCrypt.Net.BCrypt.EnhancedHashPassword(user.Password),
                    UserName       = user.UserName,
                    AccountBalance = CommonConstants.DefaultCreditBalance
                });

                int pk;
                if (_emailIdRepo.AsQueryable().Count() <= 0)
                {
                    pk = 0;
                }
                else
                {
                    pk = _emailIdRepo.AsQueryable().Max(x => x.EmailPk);
                }

                _emailIdRepo.Add(new EmailAddress {
                    EmailPk       = pk + 1,
                    UserId        = userId,
                    IsPrimaryMail = CommonConstants.True,
                    EmailAddress1 = user.DefaultEmail,
                    Status        = CommonConstants.StatusTypes.Pending
                });

                token = GenerateJwtToken(userId);
                if (user.FirstName == "Admin" && user.MiddleName == "Admin" && user.LastName == "Admin")
                {
                    token  = "";
                    userId = "";
                }
                return(true);
            }
            catch (Exception ex)
            {
                _userRepo.Rollback();

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

                _crashLogRepo.Add(new Crashlog
                {
                    CrashLogId   = pk,
                    ClassName    = "UserService",
                    MethodName   = "SignUp",
                    ErrorMessage = ex.Message,
                    ErrorInner   = (string.IsNullOrEmpty(ex.Message) || ex.Message == CommonConstants.MsgInInnerException ? ex.InnerException.Message : ex.Message),
                    Data         = user.ToString(),
                    TimeStamp    = DateTime.Now
                });
                return(false);
            }
        }
コード例 #5
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);
            }
        }