コード例 #1
0
ファイル: SongBLL.cs プロジェクト: ezetrivium/MUSICGO
        public void CountPlayback(SongViewModel song)
        {
            SongDAL songDAL = new SongDAL();
            var     songBE  = songDAL.GetById(song.Id);

            var count = CacheManager.GetWithTimeout("songvoted" + songBE.Id + "-" + songBE.User.Id);

            if (count == null || Convert.ToInt32(count) < 5)
            {
                if (count == null)
                {
                    CacheManager.SetWithTimeout("songvoted" + songBE.Id + "-" + songBE.User.Id, 0, TimeSpan.FromDays(7));
                }
                else
                {
                    CacheManager.Set("songvoted" + songBE.Id + "-" + songBE.User.Id, Convert.ToInt32(CacheManager.Get("songvoted" + songBE.Id + "-" + songBE.User.Id)) + 1);
                }

                if (songDAL.CountPlayback(songBE))
                {
                    DVVerifier dVVerifier = new DVVerifier();
                    UserDAL    userdal    = new UserDAL();
                    var        userDVH    = userdal.GetDVHEntity(songBE.User.Id);
                    userDVH.DVH = dVVerifier.DVHCalculate(userDVH);
                    userdal.SetDVH(userDVH);
                    dVVerifier.DVCalculate("UserDAL");
                }
            }
        }
コード例 #2
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public override bool Delete(Guid id)
        {
            try
            {
                BinnacleSL binnacleSL = new BinnacleSL();
                DVVerifier dvvv       = new DVVerifier();
                var        entityold  = this.Dal.GetById(id);

                bool result;
                result = this.Dal.Delete(id);
                if (!result)
                {
                    throw new BusinessException(Messages.ErrorDeleteUser);
                }

                FileUtils.DeleteImageFile(entityold.ImgKey);
                dvvv.DVCalculate("UserDAL");


                var identityClaims = (ClaimsIdentity)HttpContext.Current.User.Identity;

                string userObj = identityClaims.FindFirst("userObject").Value;



                binnacleSL.AddBinnacle(new BinnacleBE()
                {
                    User        = JsonConvert.DeserializeObject <UserBE>(userObj),
                    Description = "Delete User " + id,
                });

                return(result);
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }
コード例 #3
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public void UpdatePassword(RecoverPasswordViewModel viewModel)
        {
            try
            {
                if (viewModel.Password == viewModel.ConfirmPassword)
                {
                    PermissionsBLL permissionBLL = new PermissionsBLL();
                    UserDAL        userDAL       = new UserDAL();
                    BinnacleSL     binnacleSL    = new BinnacleSL();
                    UserBE         userBE        = new UserBE();
                    userBE.UserName = viewModel.UserName;
                    userBE          = CheckUserName(userBE);
                    DVVerifier dvvv = new DVVerifier();

                    if (CacheManager.GetWithTimeout("ResetPassword" + userBE.Id.ToString()) != null)
                    {
                        string code = CacheManager.GetWithTimeout("ResetPassword" + userBE.Id.ToString()).ToString();

                        if (code == viewModel.Code)
                        {
                            Encryptor encryptor = new Encryptor();
                            userBE.Password = encryptor.Encrypt(viewModel.Password);

                            userBE.Permissions = permissionBLL.GetUserPermission(userBE);

                            if (userDAL.Update(userBE))
                            {
                                UserDAL userdal = new UserDAL();
                                var     userDVH = userdal.GetDVHEntity(userBE.Id);
                                userDVH.DVH = dvvv.DVHCalculate(userDVH);
                                userdal.SetDVH(userDVH);
                                dvvv.DVCalculate("UserDAL");

                                binnacleSL.AddBinnacle(new BinnacleBE()
                                {
                                    User        = userBE,
                                    Description = "UpdatePassword"
                                });
                            }
                            else
                            {
                                throw new BusinessException(Messages.ErrorUpdatePassword);
                            }
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    throw new BusinessException(Messages.InvalidUpdatePasswordRequest);
                }
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }
コード例 #4
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public override bool Update(UserViewModel viewModel)
        {
            try
            {
                if (this.IsValid(viewModel))
                {
                    UserBE entity;
                    entity = Mapper.Map <UserViewModel, UserBE>(viewModel);
                    BinnacleSL binnacleSL = new BinnacleSL();
                    DVVerifier dvvv       = new DVVerifier();
                    Encryptor  encryptor  = new Encryptor();


                    var entityold = this.Dal.GetById(entity.Id);
                    var newentity = this.CheckUserName(entity);

                    if (newentity.Id == Guid.Empty || entity.UserName == entityold.UserName)
                    {
                        if (!ValidImage(viewModel))
                        {
                            throw new BusinessException(Messages.InvalidImageFormat);
                            //PROBAR
                        }

                        if (viewModel.File != null)
                        {
                            var guid = Guid.NewGuid().ToString();
                            FileUtils.DeleteImageFile(entityold.ImgKey);
                            string path = FileUtils.GetRepoImagePath(guid + Path.GetExtension(viewModel.File.FileName));
                            viewModel.File.SaveAs(path);

                            entity.ImgKey = guid + Path.GetExtension(viewModel.File.FileName);
                        }
                        PermissionDAL permissionDAL = new PermissionDAL();

                        if (entity.Contract != null && entity.Contract.Service.Id != Guid.Empty && (entityold.Contract == null || (entity.Contract.Service.Id != entityold.Contract.Service.Id || entityold.Contract.ExpirationDate < DateTime.Now)))
                        {
                            entity.Permissions = permissionDAL.GetServicePermissions(entity.Contract.Service);
                        }
                        else
                        {
                            entity.Contract = null;
                            if (entityold.Contract != null)
                            {
                                entity.Permissions = permissionDAL.GetUserPermissions(entity);
                            }
                        }

                        if (entity.Password != entityold.Password)
                        {
                            entity.Password = encryptor.Encrypt(entity.Password);
                        }

                        bool result = this.Dal.Update(entity);
                        if (result)
                        {
                            UserDAL userdal = new UserDAL();
                            var     userDVH = userdal.GetDVHEntity(entity.Id);
                            userDVH.DVH = dvvv.DVHCalculate(userDVH);
                            userdal.SetDVH(userDVH);
                            dvvv.DVCalculate("UserDAL");

                            if (HttpContext.Current.User.Identity.IsAuthenticated)
                            {
                                var    identityClaims = (ClaimsIdentity)HttpContext.Current.User.Identity;
                                string userObj        = identityClaims.FindFirst("userObject").Value;

                                binnacleSL.AddBinnacle(new BinnacleBE()
                                {
                                    User        = JsonConvert.DeserializeObject <UserBE>(userObj),
                                    Description = "Update User",
                                });
                            }
                            else
                            {
                                binnacleSL.AddBinnacle(new BinnacleBE()
                                {
                                    User        = userdal.GetById(entity.Id),
                                    Description = "Update User",
                                });
                            }


                            return(true);
                        }
                        throw new BusinessException(Messages.ErrorUpdateUser);
                    }
                    else
                    {
                        throw new BusinessException(Messages.UserExists);
                    }
                }
                else
                {
                    throw new BusinessException(Messages.InvalidData);
                }
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }
コード例 #5
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public UserViewModel LogIn(UserViewModel viewModel)
        {
            try
            {
                UserBE         userBE        = Mapper.Map <UserViewModel, UserBE>(viewModel);
                PermissionsBLL permissionBLL = new PermissionsBLL();
                BinnacleSL     binnacleSL    = new BinnacleSL();
                UserBE         userLogin     = new UserBE();
                Encryptor      encryptor     = new Encryptor();
                DVVerifier     dVVerifier    = new DVVerifier();
                UserDAL        userDAL       = new UserDAL();
                userLogin = CheckUserName(userBE);
                if (userLogin.Id != Guid.Empty)
                {
                    if (encryptor.CheckEncryption(encryptor.Encrypt(viewModel.Password), userLogin.Password))
                    {
                        if (userLogin.Contract != null && userLogin.Contract.ExpirationDate < DateTime.Now)
                        {
                            userDAL.DeleteContract(userLogin.Id);
                            userLogin.Contract = null;
                        }

                        userLogin.Permissions = permissionBLL.GetUserPermission(userLogin);

                        if (VerifyLoginPermission(userLogin.Permissions))
                        {
                            if (!userLogin.Blocked)
                            {
                                binnacleSL.AddBinnacle(new BinnacleBE()
                                {
                                    User        = userLogin,
                                    Description = "Login",
                                });

                                dVVerifier.DVVerify();

                                var language = new LanguageBLL().GetById(userLogin.Language.Id);


                                userLogin.Language = Mapper.Map <LanguageViewModel, LanguageBE>(language);

                                UserViewModel uservm = Mapper.Map <UserBE, UserViewModel>(userLogin);

                                List <PermissionViewModel> pervmList = new List <PermissionViewModel>();

                                permissionBLL.CastPermissions(userLogin.Permissions, pervmList);

                                uservm.Permissions = pervmList;

                                var file = FileUtils.GetImageBytes(FileUtils.GetRepoImagePath(uservm.ImgKey));
                                uservm.ImageBase64 = "data:image/jpg;base64," + Convert.ToBase64String(file);
                                return(uservm);
                            }
                            else
                            {
                                throw new BusinessException(Messages.User_Blocked);
                            }
                        }
                        else
                        {
                            throw new BusinessException(Messages.LoginNotOk);
                        }
                    }
                    else
                    {
                        var attempsLogin = "******" + userLogin.Id;
                        if (!CacheManager.HasKey(attempsLogin))
                        {
                            CacheManager.SetWithTimeout(attempsLogin, 0, TimeSpan.FromMinutes(30));
                        }

                        CacheManager.Set(attempsLogin, Convert.ToInt32(CacheManager.GetWithTimeout(attempsLogin)) + 1);


                        if (CacheManager.HasKey(attempsLogin) && Convert.ToInt32(CacheManager.GetWithTimeout(attempsLogin)) > 3)
                        {
                            this.Block(userLogin);
                            CacheManager.Remove(attempsLogin);
                            binnacleSL.AddBinnacle(new BinnacleBE()
                            {
                                User        = userLogin,
                                Description = "UserBlocked",
                            });
                            throw new BusinessException(Messages.User_Blocked);
                        }

                        throw new BusinessException(Messages.PasswordNotOk);
                    }
                }
                else
                {
                    throw new BusinessException(Messages.UserNotExists);
                }
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }
コード例 #6
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public override Guid Add(UserViewModel viewModel)
        {
            try
            {
                if (this.IsValid(viewModel))
                {
                    UserBE entity;
                    entity = Mapper.Map <UserViewModel, UserBE>(viewModel);
                    BinnacleSL binnacleSL = new BinnacleSL();
                    DVVerifier dvvv       = new DVVerifier();
                    Encryptor  encryptor  = new Encryptor();

                    var entitynew = this.CheckUserName(entity);

                    if (entitynew.Id == Guid.Empty)
                    {
                        if (!ValidImage(viewModel))
                        {
                            throw new BusinessException(Messages.InvalidImageFormat);
                            //PROBAR
                        }

                        if (viewModel.File != null)
                        {
                            var    guid = Guid.NewGuid().ToString();
                            string path = FileUtils.GetRepoImagePath(guid + Path.GetExtension(viewModel.File.FileName));
                            viewModel.File.SaveAs(path);

                            entity.ImgKey = guid + Path.GetExtension(viewModel.File.FileName);
                        }


                        PermissionDAL permissionDAL = new PermissionDAL();

                        if (entity.Contract.Service.Id == Guid.Empty)
                        {
                            entity.Permissions.Add(permissionDAL.GetLoginPermission());
                        }
                        else
                        {
                            entity.Permissions = permissionDAL.GetServicePermissions(entity.Contract.Service);
                        }



                        entity.Password = encryptor.Encrypt(entity.Password);

                        Guid result = this.Dal.Add(entity);



                        if (result != Guid.Empty)
                        {
                            UserDAL userdal = new UserDAL();
                            var     userDVH = userdal.GetDVHEntity(result);
                            userDVH.DVH = dvvv.DVHCalculate(userDVH);
                            userdal.SetDVH(userDVH);
                            dvvv.DVCalculate("UserDAL");



                            binnacleSL.AddBinnacle(new BinnacleBE()
                            {
                                User        = entity,
                                Description = "Add User",
                            });


                            return(result);
                        }
                        throw new BusinessException(Messages.ErrorAddUser);
                    }
                    else
                    {
                        throw new BusinessException(Messages.UserExists);
                    }
                }
                else
                {
                    throw new BusinessException(Messages.InvalidData);
                }
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }