示例#1
0
        public List <CategoryModel> AddCategory(CategoryModel category)
        {
            try
            {
                _categoryRepo.Add(new DataLayer.Entities.Category
                {
                    CategoryName     = category.CategoryName,
                    OutletId         = category.outletId,
                    ParentCategoryId = null,
                    Status           = CommonConstants.StatusTypes.Active
                });

                return(GetCategoriesByOutlets(category.outletId));
            }
            catch (Exception ex)
            {
                _categoryRepo.Rollback();

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

                return(null);
            }
        }
示例#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);
            }
        }
        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);
        }
示例#4
0
 public bool Subscribe(string UserId, int SubscriptionId)
 {
     try
     {
         IQueryable <SubscriptionLog> subscriptionLogs = _subscriptionLogRepo.AsQueryable().Where(x => x.UserId == UserId && x.SubscriptionId == SubscriptionId && x.ExpirationDate > DateTime.Today);
         Service subscriptions = _subscriptionRepo.Get(SubscriptionId);
         if (subscriptionLogs == null)
         {
             _subscriptionLogRepo.Add(new SubscriptionLog
             {
                 SubscriptionId   = SubscriptionId,
                 SubscriptionDate = DateTime.Now,
                 ExpirationDate   = DateTime.Now.AddMonths((int)_subscriptionRepo.Get(SubscriptionId).DurationMonths),
                 UserId           = UserId
             });
         }
         else
         {
             foreach (SubscriptionLog subscription in subscriptionLogs)
             {
                 subscription.ExpirationDate = DateTime.Now.AddMonths((int)_subscriptionRepo.Get(SubscriptionId).DurationMonths);
                 _subscriptionLogRepo.Update(subscription);
             }
         }
         return(true);
     } catch (Exception ex) {
         _crashLogRepo.Add(new Crashlog
         {
             ClassName    = "SubscriptionService",
             Data         = UserId.ToString() + " " + SubscriptionId.ToString(),
             ErrorInner   = ex.InnerException != null ? ex.InnerException.Message : "",
             ErrorMessage = ex.Message,
             MethodName   = "Subscribe",
             TimeStamp    = DateTime.Now
         });
         return(false);
     }
 }
示例#5
0
        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);
            }
        }
示例#6
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);
            }
        }