Esempio n. 1
0
        public ActionResult LoginPartial()
        {
            string login = User.Identity.Name;

            LoginPartialVM loginPartial;

            using (BankDB bankDB = new BankDB())
            {
                EmployeesDTO employeesDTO = bankDB.Employees.FirstOrDefault(x => x.EmployeeLogin == login);
                ClientsDTO   clientsDTO   = bankDB.Clients.FirstOrDefault(x => x.ClientLogin == login);

                if (employeesDTO == null)
                {
                    loginPartial = new LoginPartialVM()
                    {
                        FirstName = clientsDTO.ClientName,
                        Surname   = clientsDTO.ClientSurname
                    };
                }
                else
                {
                    loginPartial = new LoginPartialVM()
                    {
                        FirstName = employeesDTO.EmployeeName,
                        Surname   = employeesDTO.EmployeeSurname
                    };
                }

                return(PartialView("_LoginPartial", loginPartial));
            }
        }
Esempio n. 2
0
        public ActionResult BlockClient(int idClient, string reason)
        {
            using (BankDB bankDB = new BankDB())
            {
                ClientsDTO clientsDTO = bankDB.Clients.FirstOrDefault(x => x.ClientId == idClient);

                BlackListDTO blackListDTO = new BlackListDTO();

                blackListDTO.ClientId = clientsDTO.ClientId;
                blackListDTO.Login    = clientsDTO.ClientLogin;
                blackListDTO.Name     = clientsDTO.ClientName;
                blackListDTO.Surname  = clientsDTO.ClientSurname;
                blackListDTO.Email    = clientsDTO.ClientEmail;
                blackListDTO.Phone    = clientsDTO.ClientPhone;
                blackListDTO.Reason   = reason;
                clientsDTO.BanStatus  = true;

                bankDB.BlackLists.Add(blackListDTO);
                bankDB.SaveChanges();
            }

            TempData["OK"] = "Клиент занесен в черный список";

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        protected void Application_AuthenticateRequest()
        {
            if (User == null)
            {
                return;
            }

            string login = Context.User.Identity.Name;

            string[] roles = null;

            using (BankDB bankDB = new BankDB())
            {
                ClientsDTO   clientsDTO   = bankDB.Clients.FirstOrDefault(x => x.ClientLogin == login);
                EmployeesDTO employeesDTO = bankDB.Employees.FirstOrDefault(x => x.EmployeeLogin == login);

                if (clientsDTO != null)
                {
                    roles = bankDB.UserRoles.Where(x => x.UserId == clientsDTO.ClientId).Select(x => x.RoleClient.Name).ToArray();
                }
                else
                {
                    roles = bankDB.ListEmployeeRoles.Where(x => x.EmployeeId == employeesDTO.EmployeeId).Select(x => x.RoleEmployee.Name).ToArray();
                }
            }

            IIdentity  clientIdentity  = new GenericIdentity(login);
            IPrincipal newClientObject = new GenericPrincipal(clientIdentity, roles);

            Context.User = newClientObject;
        }
Esempio n. 4
0
        public ClientsDTO AddClient(ClientsDTO newClient)
        {
            var modelClient = _mapper.Map <Clients>(newClient);

            _context.Clients.Add(modelClient);
            _context.SaveChanges();

            return(_mapper.Map <ClientsDTO>(modelClient));
        }
Esempio n. 5
0
 public bool IsClientExist(ClientsDTO newClient)
 {
     if (_context.Clients.Any(x => x.FirstName == newClient.FirstName &&
                              x.LastName == newClient.LastName &&
                              x.PhoneNumber == newClient.PhoneNumber))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 6
0
        public IActionResult Create([FromBody] ClientsDTO newClient)
        {
            if (_clientsData.IsClientExist(newClient))
            {
                return(BadRequest());
            }

            var result = _clientsData.AddClient(newClient);

            return(StatusCode(201));
        }
        public ActionResult EditClientProfile()
        {
            string login = User.Identity.Name;

            ClientProfileVM clientProfile;

            using (BankDB bankDB = new BankDB())
            {
                ClientsDTO clientsDTO = bankDB.Clients.FirstOrDefault(x => x.ClientLogin == login);

                clientProfile = new ClientProfileVM(clientsDTO);
            }

            return(View(clientProfile));
        }
        public ActionResult ClientDetails()
        {
            string login = User.Identity.Name;

            ClientVM clientVM;

            using (BankDB bankDB = new BankDB())
            {
                ClientsDTO clientsDTO = bankDB.Clients.FirstOrDefault(x => x.ClientLogin == login);

                clientVM = new ClientVM(clientsDTO);
            }

            return(View("ClientDetails", clientVM));
        }
Esempio n. 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            ClientsDTO client       = new ClientsDTO();
            string     errorMessage = null;

            client.FirstName     = TBName.Text;
            client.LastName      = TBSurname.Text;
            client.Phone         = TBPhone.Text;
            client.Email         = TBMail.Text;
            client.PostalCode    = TBCP.Text;
            client.StreetAddress = TBAddress.Text;
            client.City          = TBCity.Text;
            ClientsDTO.CreateProductAsync(client);
            MessageBox.Show("valider");
        }
Esempio n. 10
0
 public ClientProfileVM(ClientsDTO row)
 {
     ClientId       = row.ClientId;
     ClientName     = row.ClientName;
     ClientSurname  = row.ClientSurname;
     ClientAge      = row.ClientAge;
     ClientEmail    = row.ClientEmail;
     ClientPhone    = row.ClientPhone;
     Balance        = row.Balance;
     EmployeeId     = row.EmployeeId;
     MyEmployee     = row.MyEmployee;
     Credit         = row.Credit;
     Deposit        = row.Deposit;
     ClientLogin    = row.ClientLogin;
     ClientPassword = row.ClientPassword;
 }
Esempio n. 11
0
        public async Task <IActionResult> Put(int id, ClientsDTO clientDto)
        {
            try
            {
                var client = _mapper.Map <Clients>(clientDto);
                client.Client_Id = id;
                await _clientsServices.Update(client);

                var response = new GenericResponse <bool>(true);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                throw new BusinessException(MessageCodes.PROPERTY_NO_VALID, GetErrorDescription(MessageCodes.PROPERTY_NO_VALID), ex.Message);
            }
        }
Esempio n. 12
0
        public ActionResult Unblock(int id, int clientId)
        {
            using (BankDB bankDB = new BankDB())
            {
                BlackListDTO blackList  = bankDB.BlackLists.Find(id);
                ClientsDTO   clientsDTO = bankDB.Clients.Find(clientId);

                clientsDTO.BanStatus = false;

                bankDB.BlackLists.Remove(blackList);
                bankDB.SaveChanges();
            }

            TempData["OK"] = "Клиент восстановлен!";

            return(RedirectToAction("Index"));
        }
Esempio n. 13
0
        public async Task <IActionResult> Post([FromBody] ClientsDTO clientDto)
        {
            try
            {
                var client = _mapper.Map <Clients>(clientDto);
                await _clientsServices.Add(client);

                clientDto = _mapper.Map <ClientsDTO>(client);

                var response = new GenericResponse <ClientsDTO>(clientDto);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                throw new BusinessException(MessageCodes.PROPERTY_NO_VALID, GetErrorDescription(MessageCodes.PROPERTY_NO_VALID), ex.Message);
            }
        }
Esempio n. 14
0
        public ActionResult UserDetails()
        {
            string login = User.Identity.Name;

            using (BankDB bankDB = new BankDB())
            {
                EmployeesDTO employeesDTO = bankDB.Employees.FirstOrDefault(x => x.EmployeeLogin == login);
                ClientsDTO   clientsDTO   = bankDB.Clients.FirstOrDefault(x => x.ClientLogin == login);

                if (employeesDTO == null)
                {
                    return(RedirectToAction("ManagerDetails", "Employees"));
                }
                else
                {
                    return(RedirectToAction("ClientDetails", "Clients"));
                }
            }
        }
Esempio n. 15
0
        public ActionResult EditClient(int id)
        {
            ClientProfileVM clientVM;

            using (BankDB bankDB = new BankDB())
            {
                ClientsDTO clientsDTO = bankDB.Clients.Find(id);

                if (clientsDTO == null)
                {
                    return(Content("Не доступно"));
                }

                clientVM = new ClientProfileVM(clientsDTO);

                clientVM.employeeList = new SelectList(bankDB.Employees.ToList(), "EmployeeId", "EmployeeSurname");
            }

            return(View(clientVM));
        }
Esempio n. 16
0
        public List <ClientsDTO> GetClients()
        {
            List <ClientsDTO> lLstClientsDTO = new List <ClientsDTO>();
            Recordset         lObjRecordset  = null;

            try
            {
                lObjRecordset = (Recordset)DIApplication.Company.GetBusinessObject(BoObjectTypes.BoRecordset);

                string lStrQuery = this.GetSQL("GetClients");

                lObjRecordset.DoQuery(lStrQuery);

                if (lObjRecordset.RecordCount > 0)
                {
                    for (int i = 0; i < lObjRecordset.RecordCount; i++)
                    {
                        ClientsDTO lObjClientsDTO = new ClientsDTO
                        {
                            CardCode = lObjRecordset.Fields.Item("CardCode").Value.ToString(),
                            CardName = lObjRecordset.Fields.Item("CardName").Value.ToString(),
                        };

                        lLstClientsDTO.Add(lObjClientsDTO);
                        lObjRecordset.MoveNext();
                    }
                }
            }
            catch (Exception lObjException)
            {
                LogService.WriteError(string.Format("[ClientsDAO - GetClients: {0}]", lObjException.Message));
                throw new DAOException(lObjException.Message, lObjException);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjRecordset);
            }
            return(lLstClientsDTO);
        }
Esempio n. 17
0
        public ActionResult EditClient(ClientProfileVM clientVM)
        {
            int id = clientVM.ClientId;

            using (BankDB bankDB = new BankDB())
            {
                clientVM.employeeList = new SelectList(bankDB.Employees.ToList(), "EmployeeId", "EmployeeSurname");
            }

            if (!ModelState.IsValid)
            {
                return(View(clientVM));
            }

            using (BankDB bankDB = new BankDB())
            {
                ClientsDTO clientsDTO = bankDB.Clients.Find(id);

                if (clientsDTO.EmployeeId != clientVM.EmployeeId)
                {
                    EmployeesDTO oldEmployee = bankDB.Employees.Where(x => x.EmployeeId == clientsDTO.EmployeeId).First();
                    oldEmployee.ClientsCount -= 1;

                    clientsDTO.EmployeeId = clientVM.EmployeeId;
                    clientsDTO.Balance    = clientVM.Balance;

                    EmployeesDTO newEmployee = bankDB.Employees.FirstOrDefault(x => x.EmployeeId == clientVM.EmployeeId);
                    newEmployee.ClientsCount += 1;
                    clientsDTO.MyEmployee     = $"{newEmployee.EmployeeName} {newEmployee.EmployeeSurname}";

                    bankDB.SaveChanges();

                    TempData["OK"] = "Информация изменена";
                }
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult CreateEmployeeClient(ClientVM clientVM)
        {
            string login = User.Identity.Name;

            if (!ModelState.IsValid)
            {
                return(View("CreateEmployeeClient", clientVM));
            }

            using (BankDB bankDB = new BankDB())
            {
                EmployeesDTO employeesDTO = bankDB.Employees.FirstOrDefault(x => x.EmployeeLogin == login);

                if (bankDB.Clients.Any(x => x.ClientLogin == clientVM.ClientLogin))
                {
                    ModelState.AddModelError("loginExist", $"Логин {clientVM.ClientLogin} занят");

                    return(View("CreateEmployeeClient", clientVM));
                }
                else if (bankDB.Clients.Any(x => x.ClientEmail == clientVM.ClientEmail))
                {
                    ModelState.AddModelError("emailExist", "Этот адрес занят");

                    return(View("CreateEmployeeClient", clientVM));
                }
                else if (bankDB.Clients.Any(x => x.ClientPhone == clientVM.ClientPhone))
                {
                    ModelState.AddModelError("phoneExist", "Номер телефона уже используется");

                    return(View("CreateEmployeeClient", clientVM));
                }

                int    employeeId = employeesDTO.EmployeeId;
                string manager    = $"{employeesDTO.EmployeeName} {employeesDTO.EmployeeSurname}";

                ClientsDTO clientsDTO = new ClientsDTO()
                {
                    ClientName     = clientVM.ClientName,
                    ClientSurname  = clientVM.ClientSurname,
                    ClientAge      = clientVM.ClientAge,
                    ClientEmail    = clientVM.ClientEmail,
                    ClientPhone    = clientVM.ClientPhone,
                    Balance        = clientVM.Balance,
                    Credit         = clientVM.Credit,
                    Deposit        = clientVM.Deposit,
                    ClientLogin    = clientVM.ClientLogin,
                    ClientPassword = clientVM.ClientPassword,
                    EmployeeId     = employeeId,
                    MyEmployee     = manager
                };

                employeesDTO.ClientsCount += 1;

                bankDB.Clients.Add(clientsDTO);
                bankDB.SaveChanges();

                int id   = clientsDTO.ClientId;
                int role = clientsDTO.Balance < 50000 ? 1 : clientsDTO.Balance >= 50000 ? 2 : clientsDTO.Balance > 200000 ? 3 : 3;

                UserRoleDTO userRole = new UserRoleDTO()
                {
                    UserId = id,
                    RoleId = role
                };

                bankDB.UserRoles.Add(userRole);
                bankDB.SaveChanges();
            }

            TempData["OK"] = "Аккаунт создан";

            return(RedirectToAction("manager-details", "Employees"));
        }
Esempio n. 19
0
 public async Task AddClients([FromBody] ClientsDTO Client)
 {
     var client = _mapper.Map <ClientsDTO, Clients>(Client);
     await _ClientsService.AddClients(client);
 }
        public ActionResult CreateAccount(ClientVM clientVM)
        {
            Random random = new Random();

            if (!ModelState.IsValid)
            {
                return(View("CreateAccount", clientVM));
            }

            using (BankDB bankDB = new BankDB())
            {
                if (bankDB.Clients.Any(x => x.ClientLogin == clientVM.ClientLogin))
                {
                    ModelState.AddModelError("loginExist", $"Логин {clientVM.ClientLogin} занят");

                    return(View("CreateAccount", clientVM));
                }
                else if (bankDB.Clients.Any(x => x.ClientEmail == clientVM.ClientEmail))
                {
                    ModelState.AddModelError("emailExist", "Этот адрес занят");

                    return(View("CreateAccount", clientVM));
                }
                else if (bankDB.Clients.Any(x => x.ClientPhone == clientVM.ClientPhone))
                {
                    ModelState.AddModelError("phoneExist", "Номер телефона уже используется");

                    return(View("CreateAccount", clientVM));
                }

                Dictionary <int, string> Employee = new Dictionary <int, string>();

                foreach (var item in bankDB.Employees.Where(x => x.EmployeePosition != "Администратор"))
                {
                    Employee.Add(item.EmployeeId, $"{item.EmployeeName} {item.EmployeeSurname}");
                }

                int    employeeId = Employee.ElementAt(random.Next(0, Employee.Count)).Key;
                string manager    = Employee[employeeId];

                ClientsDTO clientsDTO = new ClientsDTO()
                {
                    ClientName     = clientVM.ClientName,
                    ClientSurname  = clientVM.ClientSurname,
                    ClientAge      = clientVM.ClientAge,
                    ClientEmail    = clientVM.ClientEmail,
                    ClientPhone    = clientVM.ClientPhone,
                    ClientLogin    = clientVM.ClientLogin,
                    ClientPassword = clientVM.ClientPassword,
                    EmployeeId     = employeeId,
                    MyEmployee     = manager
                };

                EmployeesDTO employeesDTO = bankDB.Employees.Find(employeeId);
                employeesDTO.ClientsCount += 1;

                bankDB.Clients.Add(clientsDTO);
                bankDB.SaveChanges();

                int id   = clientsDTO.ClientId;
                int role = clientsDTO.Balance < 50000 ? 1 : clientsDTO.Balance >= 50000 ? 2 : clientsDTO.Balance > 200000 ? 3 : 3;

                UserRoleDTO userRole = new UserRoleDTO()
                {
                    UserId = id,
                    RoleId = role
                };

                bankDB.UserRoles.Add(userRole);
                bankDB.SaveChanges();
            }

            TempData["OK"] = "Аккаунт создан";

            return(RedirectToAction("Login", "Login"));
        }
        public ActionResult EditClientProfile(ClientProfileVM clientProfile)
        {
            bool loginIsChanged = false;

            if (!ModelState.IsValid)
            {
                return(View("EditClientProfile", clientProfile));
            }

            if (!string.IsNullOrEmpty(clientProfile.ClientPassword))
            {
                if (!clientProfile.ClientPassword.Equals(clientProfile.ConfirmPassword))
                {
                    ModelState.AddModelError("errorPass", "пароли не совпадают");
                    clientProfile.ConfirmPassword = "";
                    clientProfile.ConfirmPassword = "";

                    return(View("EditClientProfile", clientProfile));
                }
            }

            using (BankDB bankDB = new BankDB())
            {
                string login = User.Identity.Name;

                if (login != clientProfile.ClientLogin)
                {
                    login          = clientProfile.ClientLogin;
                    loginIsChanged = true;
                }

                if (bankDB.Clients.Where(x => x.ClientId != clientProfile.ClientId).Any(x => x.ClientLogin == login))
                {
                    ModelState.AddModelError("loginMatch", $"Логин {clientProfile.ClientLogin} занят");

                    return(View("EditClientProfile", clientProfile));
                }
                else if (bankDB.Clients.Where(x => x.ClientId != clientProfile.ClientId).Any(x => x.ClientEmail == clientProfile.ClientEmail))
                {
                    ModelState.AddModelError("emailMatch", "Email занят");

                    return(View("EditClientProfile", clientProfile));
                }
                else if (bankDB.Clients.Where(x => x.ClientId != clientProfile.ClientId).Any(x => x.ClientPhone == clientProfile.ClientPhone))
                {
                    ModelState.AddModelError("phoneMatch", "Телефон занят");

                    return(View("EditClientProfile", clientProfile));
                }

                ClientsDTO clientsDTO = bankDB.Clients.Find(clientProfile.ClientId);

                clientsDTO.ClientName    = clientProfile.ClientName;
                clientsDTO.ClientSurname = clientProfile.ClientSurname;
                clientsDTO.ClientAge     = clientProfile.ClientAge;
                clientsDTO.ClientEmail   = clientProfile.ClientEmail;
                clientsDTO.ClientPhone   = clientProfile.ClientPhone;
                clientsDTO.ClientLogin   = clientProfile.ClientLogin;

                if (!string.IsNullOrEmpty(clientProfile.ClientPassword))
                {
                    clientsDTO.ClientPassword = clientProfile.ClientPassword;
                }

                bankDB.SaveChanges();
            }

            TempData["OK"] = "Данные обновлены";

            if (!loginIsChanged)
            {
                return(View("EditClientProfile", clientProfile));
            }
            else
            {
                return(RedirectToAction("LogOut"));
            }
        }