示例#1
0
        public DeleteOrgAccountViewModel DeleteOrganizationAccount(DeleteOrgAccountViewModel model)
        {
            try
            {
                var  userRole = this._unitOfWork.MembershipRepository.GetRole(model.UserId);
                User user     = this._unitOfWork.UsersRepository.Get(model.UserId);

                if (user.Password == PasswordHashManager.GetPasswordHash(user.Salt, model.AdministratorPassword))
                {
                    if (this._unitOfWork.MembershipRepository.GetOrganizationId(model.UserId) == model.OrganizationId && userRole == "admin")
                    {
                        var orgAccount = this._unitOfWork.OrganizationAccountRepository.Read(model.OrgAccountId);
                        this._unitOfWork.OrganizationAccountRepository.Delete(model.OrgAccountId);
                        if (orgAccount.AccountType == "Банк")
                        {
                            var bankAccount = this._unitOfWork.BankAccountRepository.Get(orgAccount.BankAccount.Id);
                            this._unitOfWork.BankAccountRepository.Delete(bankAccount.Id);
                        }
                        this._unitOfWork.SaveChanges();
                        return(new DeleteOrgAccountViewModel());
                    }
                    else
                    {
                        return(new DeleteOrgAccountViewModel
                        {
                            Error = ErrorMessages.YouArentAdminOfThisOrganization
                        });
                    }
                }
                else
                {
                    return(new DeleteOrgAccountViewModel
                    {
                        Error = ErrorMessages.WrongAdminPasswond
                    });
                }
            }
            catch (Exception e)
            {
                return(new DeleteOrgAccountViewModel
                {
                    Error = e.Message
                });
            }
        }
示例#2
0
 public DeleteOrgAccountViewModel DeleteOrganizationAccount(DeleteOrgAccountViewModel model)
 {
     try
     {
         var  userRole = this._unitOfWork.MembershipRepository.GetRole(model.UserId);
         User user     = this._unitOfWork.UsersRepository.Get(model.UserId);
         if (user.Password == PasswordHashManager.GetPasswordHash(model.AdministratorPassword))
         {
             if (this._unitOfWork.MembershipRepository.GetOrganizationId(model.UserId) == model.OrganizationId && userRole == "admin")
             {
                 var orgAccount = this._unitOfWork.OrganizationAccountRepository.Read(model.OrgAccountId);
                 this._unitOfWork.OrganizationAccountRepository.Delete(model.OrgAccountId);
                 if (orgAccount.AccountType == "Банк")
                 {
                     var bankAccount = this._unitOfWork.BankAccountRepository.Get(orgAccount.BankAccount.Id);
                     this._unitOfWork.BankAccountRepository.Delete(bankAccount.Id);
                 }
                 this._unitOfWork.SaveChanges();
                 return(new DeleteOrgAccountViewModel());
             }
             else
             {
                 return(new DeleteOrgAccountViewModel
                 {
                     Error = "Ви не адміністратор цієї організації"
                 });
             }
         }
         else
         {
             return(new DeleteOrgAccountViewModel
             {
                 Error = "Невірний пароль адміністратора організації"
             });
         }
     }
     catch (Exception e)
     {
         return(new DeleteOrgAccountViewModel
         {
             Error = e.Message
         });
     }
 }
示例#3
0
 public DeleteOrgAccountViewModel Delete([FromBody] DeleteOrgAccountViewModel model)
 {
     return(this._orgAccountService.DeleteOrganizationAccount(model));
 }