public ActionResult CreateCategory(CategoryVM categoryVM) { TextInfo text = CultureInfo.CurrentCulture.TextInfo; if (!ModelState.IsValid) { return(View(categoryVM)); } using (BankDB bankDB = new BankDB()) { if (bankDB.Categories.Any(x => x.Name == categoryVM.Name)) { ModelState.AddModelError("catNameExist", "Эта категория уже создана"); return(View(categoryVM)); } CategoriesDTO categoriesDTO = new CategoriesDTO(); categoriesDTO.Name = text.ToTitleCase(categoryVM.Name); bankDB.Categories.Add(categoriesDTO); bankDB.SaveChanges(); } TempData["OK"] = "Категория создана"; return(View(categoryVM)); }
public ActionResult EditCategory(CategoryVM categoryVM) { TextInfo text = CultureInfo.CurrentCulture.TextInfo; int id = categoryVM.Id; if (!ModelState.IsValid) { return(View(categoryVM)); } using (BankDB bankDB = new BankDB()) { CategoriesDTO categoriesDTO = bankDB.Categories.Find(id); if (bankDB.Categories.Where(x => x.Id != categoryVM.Id).Any(x => x.Name == categoryVM.Name)) { ModelState.AddModelError("nameExist", "Категория уже создана"); return(View(categoryVM)); } categoriesDTO.Name = text.ToTitleCase(categoryVM.Name); bankDB.SaveChanges(); } TempData["OK"] = "Категория изменена"; return(RedirectToAction("PageCategories")); }
//JDR: Resend newley generated ConfirmationCode to user "Email" public ActionResult ResentConfirmationCode(string Email) { using (BankDB db = new BankDB()) { var User = db.User.Where(userRow => userRow.Email == Email).FirstOrDefault(); if (User == null) { TempData["AlertTag"] = "danger"; TempData["AlertLabel"] = "Error:"; TempData["AlertMessage"] = "Incorrect email for code validation."; return(RedirectToAction("Login", "Account")); } var Confirmation = Models.EmailConfirmation.SetEmailConfirmation(User.ID); /**************************************** REMOVE ****************************************/ //JDR: TODO: Remove this: This is here just to fake user email confirmation link Session["ConfirmEmail"] = User.Email; Session["ConfirmCode"] = Confirmation.Token; /**************************************** REMOVE ****************************************/ TempData["AlertTag"] = "info"; TempData["AlertLabel"] = ""; TempData["AlertMessage"] = "Email confirmation code was sent to <b>" + User.Email + "</b>"; return(RedirectToAction("Login", "Account")); } }
public ActionResult CurrencyCalc(string firstValute, string secondValute, decimal firstValuteCount = 1) { using (BankDB bankDB = new BankDB()) { if (firstValute == null && secondValute == null) { CurrencyDTO firstCurrencyDefault = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == "AUD"); CurrencyDTO secondCurrencyDefault = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == "AUD"); ViewBag.FisrtValuteName = firstCurrencyDefault.CurrencyName; ViewBag.SecondValuteName = secondCurrencyDefault.CurrencyName; ViewBag.Result = firstCurrencyDefault.CurrencyRate * firstValuteCount / secondCurrencyDefault.CurrencyRate; return(PartialView("_CurrencyCalc")); } else { CurrencyDTO firstCurrency = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == firstValute); CurrencyDTO secondCurrency = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == secondValute); ViewBag.FisrtValuteName = firstCurrency.CurrencyName; ViewBag.SecondValuteName = secondCurrency.CurrencyName; ViewBag.Result = firstCurrency.CurrencyRate * firstValuteCount / secondCurrency.CurrencyRate; return(PartialView("_CurrencyCalc")); } } }
public ActionResult ForgotPassword(string Email) { if (!UserAccount.EmailExist(Email)) { TempData["AlertTag"] = "danger"; TempData["AlertLabel"] = "Error: "; TempData["AlertMessage"] = "Invalid Email Address"; return(View()); } string Password = System.Web.Security.Membership.GeneratePassword(10, 1); using (BankDB db = new BankDB()) { var User = db.User.Where(userRow => userRow.Email == Email).FirstOrDefault(); User.Password = GLOBAL.Hash(Password, UserAccount.PasswordSalt); User.Email = User.Email.Trim(); User.Save(); } TempData["AlertTag"] = "info"; TempData["AlertLabel"] = ""; TempData["AlertMessage"] = "A new password has been sent to <b>" + Email + "</b> <div class=\"pull-right\">" + Password + "</div>"; return(View()); }
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")); }
// GET: Pages public ActionResult Index(string page = "") { if (page == "") { page = "Home"; } PageVM pageVM; PagesDTO pagesDTO; using (BankDB bankDB = new BankDB()) { if (!bankDB.Pages.Any(x => x.Title.Equals(page))) { return(RedirectToAction("Index", new { page = "" })); } } using (BankDB bankDB = new BankDB()) { pagesDTO = bankDB.Pages.Where(x => x.Title == page).FirstOrDefault(); } ViewBag.PageTitle = pagesDTO.Title; pageVM = new PageVM(pagesDTO); return(View(pageVM)); }
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)); } }
public ActionResult CreateEmployee(EmployeeVM model) { TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo; if (!ModelState.IsValid) { using (BankDB bankDB = new BankDB()) { model.positionList = new SelectList(bankDB.EmployeeRoles.ToList(), "Id", "Name"); return(View(model)); } } using (BankDB bankDB = new BankDB()) { EmployeesDTO employeesDTO = new EmployeesDTO(); if (bankDB.Employees.Any(x => x.EmployeeLogin == model.EmployeeLogin)) { ModelState.AddModelError("loginExist", "Это имя занято, выберите другое"); return(View(model)); } employeesDTO.EmployeeName = textInfo.ToTitleCase(model.EmployeeName); employeesDTO.EmployeeSurname = textInfo.ToTitleCase(model.EmployeeSurname); employeesDTO.EmployeeAge = model.EmployeeAge; employeesDTO.EmployeeEmail = model.EmployeeEmail; employeesDTO.EmployeePhone = model.EmployeePhone; employeesDTO.EmployeeLogin = model.EmployeeLogin; employeesDTO.EmployeePassword = model.EmployeePassword; employeesDTO.EmployeePositionId = model.EmployeePositionId; EmployeeRoleDTO employeeRole = bankDB.EmployeeRoles.FirstOrDefault(x => x.Id == model.EmployeePositionId); employeesDTO.EmployeePosition = employeeRole.Name; employeesDTO.EmployeeSalary = model.EmployeeSalary; employeesDTO.ClientsCount = 0; bankDB.Employees.Add(employeesDTO); bankDB.SaveChanges(); int id = employeesDTO.EmployeeId; int roleId = bankDB.EmployeeRoles.Where(x => x.Name == employeeRole.Name).Select(x => x.Id).First(); ListEmployeeRoleDTO listRoleEmployee = new ListEmployeeRoleDTO() { EmployeeId = id, RoleEmployeeId = roleId }; bankDB.ListEmployeeRoles.Add(listRoleEmployee); bankDB.SaveChanges(); } TempData["OK"] = "Сотрудник добавлен"; return(RedirectToAction("Index")); }
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; }
public ActionResult CreatePage(PageVM pageVM) { if (!ModelState.IsValid) { using (BankDB bankDB = new BankDB()) { pageVM.categoryList = new SelectList(bankDB.Categories.ToList(), "Id", "Name"); return(View(pageVM)); } } using (BankDB bankDB = new BankDB()) { string description = null; PagesDTO pagesDTO = new PagesDTO(); pagesDTO.Title = pageVM.Title; if (string.IsNullOrWhiteSpace(pageVM.Description)) { description = pageVM.Title.Replace(" ", "-").ToLower(); } else { description = pageVM.Description.Replace(" ", "-").ToLower(); } if (bankDB.Pages.Any(x => x.Title == pageVM.Title)) { ModelState.AddModelError("titleExist", "Это имя страницы занято"); return(View(pageVM)); } else if (bankDB.Pages.Any(x => x.Description == pageVM.Description)) { ModelState.AddModelError("descrExist", "Этот адрес страницы занят"); return(View(pageVM)); } pagesDTO.Description = description; pagesDTO.Body = pageVM.Body; pagesDTO.SideBar = pageVM.Sidebar; pagesDTO.PageCategoryId = pageVM.PageCategoryId; CategoriesDTO categories = bankDB.Categories.FirstOrDefault(x => x.Id == pageVM.PageCategoryId); pagesDTO.PageCategory = categories.Name; bankDB.Pages.Add(pagesDTO); bankDB.SaveChanges(); } TempData["OK"] = "Страница создана"; return(RedirectToAction("Index")); }
public ActionResult ClientsQueryPartial(string sort, string filter) { List <ClientVM> clientsList = new List <ClientVM>(); using (BankDB bankDB = new BankDB()) { string SortQuery = string.IsNullOrEmpty(sort) ? "name_desc" : sort; switch (SortQuery) { case "name_desc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderBy(x => x.ClientName).Select(x => new ClientVM(x)).ToList(); break; case "AgeAsc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderBy(x => x.ClientAge).Select(x => new ClientVM(x)).ToList(); break; case "AgeDesc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderByDescending(x => x.ClientAge).Select(x => new ClientVM(x)).ToList(); break; case "BalanceAsc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderBy(x => x.Balance).Select(x => new ClientVM(x)).ToList(); break; case "BalanceDesc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderByDescending(x => x.Balance).Select(x => new ClientVM(x)).ToList(); break; case "CreditAsc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderBy(x => x.Credit).Select(x => new ClientVM(x)).ToList(); break; case "CreditDesc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderByDescending(x => x.Credit).Select(x => new ClientVM(x)).ToList(); break; case "DepositAsc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderBy(x => x.Deposit).Select(x => new ClientVM(x)).ToList(); break; case "DepositDesc": clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderByDescending(x => x.Deposit).Select(x => new ClientVM(x)).ToList(); break; default: clientsList = bankDB.Clients.ToArray().Where(x => x.BanStatus == false).OrderBy(x => x.ClientName).Select(x => new ClientVM(x)).ToList(); break; } if (filter != null) { clientsList = clientsList.Where(x => x.SearchInfo().ToLower().Contains(filter.ToLower())).ToList(); } } return(PartialView("_ClientsQueryPartial", clientsList)); }
public ActionResult EmployeeQueryPartial(string sort, string filter) { List <EmployeeVM> employeeList = new List <EmployeeVM>(); using (BankDB bankDB = new BankDB()) { string SortQuery = string.IsNullOrEmpty(sort) ? "name_desc" : sort; switch (SortQuery) { case "name_desc": employeeList = bankDB.Employees.ToArray().OrderBy(x => x.EmployeeName).Select(x => new EmployeeVM(x)).ToList(); break; case "AgeAsc": employeeList = bankDB.Employees.ToArray().OrderBy(x => x.EmployeeAge).Select(x => new EmployeeVM(x)).ToList(); break; case "AgeDesc": employeeList = bankDB.Employees.ToArray().OrderByDescending(x => x.EmployeeAge).Select(x => new EmployeeVM(x)).ToList(); break; case "SalaryAsc": employeeList = bankDB.Employees.ToArray().OrderBy(x => x.EmployeeSalary).Select(x => new EmployeeVM(x)).ToList(); break; case "SalaryDesc": employeeList = bankDB.Employees.ToArray().OrderByDescending(x => x.EmployeeSalary).Select(x => new EmployeeVM(x)).ToList(); break; case "Position": employeeList = bankDB.Employees.ToArray().OrderBy(x => x.EmployeePosition).Select(x => new EmployeeVM(x)).ToList(); break; case "ClientAsc": employeeList = bankDB.Employees.ToArray().OrderBy(x => x.ClientsCount).Select(x => new EmployeeVM(x)).ToList(); break; case "ClientDesc": employeeList = bankDB.Employees.ToArray().OrderByDescending(x => x.ClientsCount).Select(x => new EmployeeVM(x)).ToList(); break; default: employeeList = bankDB.Employees.ToArray().OrderBy(x => x.EmployeeName).Select(x => new EmployeeVM(x)).ToList(); break; } if (filter != null) { employeeList = employeeList.Where(x => x.Info().ToLower().Contains(filter.ToLower())).ToList(); } } return(PartialView("_EmployeeQueryPartial", employeeList)); }
public ActionResult BlackList() { List <BlackListVM> blackList = new List <BlackListVM>(); using (BankDB bankDB = new BankDB()) { blackList = bankDB.BlackLists.ToArray().OrderBy(x => x.Id).Select(x => new BlackListVM(x)).ToList(); } return(View(blackList)); }
public ActionResult CreateEmployee() { EmployeeVM employeeVM = new EmployeeVM(); using (BankDB bankDB = new BankDB()) { employeeVM.positionList = new SelectList(bankDB.EmployeeRoles.ToList(), "Id", "Name"); } return(View(employeeVM)); }
public ActionResult NewsCategory(string name) { List <PageVM> categoryList = new List <PageVM>(); using (BankDB bankDB = new BankDB()) { categoryList = bankDB.Pages.ToArray().Where(x => x.PageCategory.Equals(name)).Select(x => new PageVM(x)).ToList(); } return(View("NewsCategory", categoryList)); }
public ActionResult CreatePage() { PageVM pageVM = new PageVM(); using (BankDB bankDB = new BankDB()) { pageVM.categoryList = new SelectList(bankDB.Categories.ToList(), "Id", "Name"); } return(View(pageVM)); }
// GET: News public ActionResult Index() { List <PageVM> newsList = new List <PageVM>(); using (BankDB bankDB = new BankDB()) { newsList = bankDB.Pages.ToArray().Where(x => x.Title != "Home").Select(x => new PageVM(x)).ToList(); } return(View(newsList)); }
public ActionResult PageCategories() { List <CategoryVM> categoryList = new List <CategoryVM>(); using (BankDB bankDB = new BankDB()) { categoryList = bankDB.Categories.ToArray().OrderBy(x => x.Name).Select(x => new CategoryVM(x)).ToList(); } return(View(categoryList)); }
// GET: Admin/Page public ActionResult Index() { List <PageVM> pageList = new List <PageVM>(); using (BankDB bankDB = new BankDB()) { pageList = bankDB.Pages.ToArray().OrderBy(x => x.Title).Select(x => new PageVM(x)).ToList(); } return(View(pageList)); }
public ActionResult Index() { using (BankDB db = new BankDB()) { //return View(db.User.ToList()); } return(RedirectToRoute(new { controller = "Account", action = "Login" })); }
public bool Validate(PaymentModel pay) { // return true; BankDB fk = new BankDB(); if (fk.cc1.FindAll(x => x.cardNumber == pay.cardNumber).Count > 0) { return(true); } else { return(false); } }
public ActionResult ManagerDetails() { string login = User.Identity.Name; EmployeeVM employeeVM; using (BankDB bankDB = new BankDB()) { EmployeesDTO employeesDTO = bankDB.Employees.FirstOrDefault(x => x.EmployeeLogin == login); employeeVM = new EmployeeVM(employeesDTO); } return(View("ManagerDetails", employeeVM)); }
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 DeleteCategory(int id) { using (BankDB bankDB = new BankDB()) { CategoriesDTO categoriesDTO = bankDB.Categories.Find(id); bankDB.Categories.Remove(categoriesDTO); bankDB.SaveChanges(); } TempData["OK"] = "Категория удалена"; return(RedirectToAction("PageCategories")); }
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)); }
public ActionResult DeleteEmployee(int id) { using (BankDB bankDB = new BankDB()) { EmployeesDTO employeesDTO = bankDB.Employees.Find(id); bankDB.Employees.Remove(employeesDTO); bankDB.SaveChanges(); } TempData["OK"] = "Клиент удален"; return(RedirectToAction("Index")); }
public ActionResult DeletePage(int id) { using (BankDB bankDB = new BankDB()) { PagesDTO pagesDTO = bankDB.Pages.Find(id); bankDB.Pages.Remove(pagesDTO); bankDB.SaveChanges(); } TempData["OK"] = "Страница удалена"; return(RedirectToAction("Index")); }
public ActionResult MyClients(int id) { EmployeeVM employeeVM = new EmployeeVM(); List <ClientVM> clientsList = new List <ClientVM>(); using (BankDB bankDB = new BankDB()) { EmployeesDTO employeesDTO = bankDB.Employees.Find(id); employeeVM = new EmployeeVM(employeesDTO); clientsList = bankDB.Clients.ToArray().Where(x => x.EmployeeId == employeeVM.EmployeeId).Select(x => new ClientVM(x)).ToList(); } return(PartialView("_MyClients", clientsList)); }
public ActionResult Login(LoginVM loginVM) { if (!ModelState.IsValid) { ModelState.AddModelError("emptyField", "Введите данные"); return(View(loginVM)); } bool isEmployee = false; bool isClient = false; using (BankDB bankDB = new BankDB()) { if (bankDB.BlackLists.Any(x => x.Login == loginVM.UserName)) { ModelState.AddModelError("ban", $"Ваш аккаунт заблокирован, причина - {bankDB.BlackLists.Select(x => x.Reason).First()}"); return(View(loginVM)); } } using (BankDB bankDB = new BankDB()) { if (bankDB.Employees.Any(x => x.EmployeeLogin == loginVM.UserName && x.EmployeePassword == loginVM.Password)) { isEmployee = true; } else if (bankDB.Clients.Any(x => x.ClientLogin == loginVM.UserName && x.ClientPassword == loginVM.Password)) { isClient = true; } if (!isEmployee && !isClient) { ModelState.AddModelError("entryError", "Ошибка логина или пароля"); return(View(loginVM)); } else { FormsAuthentication.SetAuthCookie(loginVM.UserName, loginVM.RememberMy); return(Redirect(FormsAuthentication.GetRedirectUrl(loginVM.UserName, loginVM.RememberMy))); } } }