public IActionResult ShowCustomer(int id)
        {
            var model           = new AccountCustomerViewModel();
            var dispositionList = new List <Dispositions>();

            model.Customer = _context.Customers.SingleOrDefault(c => c.CustomerId == id);

            if (model.Customer == null)
            {
                ViewData["Message"] = "Kunde ej hitta kund med matchande kundnummer";
                return(View("SearchCustomerById"));
            }

            var firstDispositionList = _context.Dispositions.Where(d => d.CustomerId == id);

            dispositionList = firstDispositionList.ToList();

            foreach (var disp in dispositionList)
            {
                var acc = _context.Accounts.SingleOrDefault(a => a.AccountId == disp.AccountId);
                model.Accounts.Add(acc);
            }

            foreach (var acc in model.Accounts)
            {
                model.Total += acc.Balance;
            }

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> CustomerAccounts(int id)
        {
            List <Account>           accounts = new List <Account>();
            AccountCustomerViewModel model    = new AccountCustomerViewModel();

            model.Accounts = _context.accounts.ToList();
            model.Customer = await _context.customers.FirstOrDefaultAsync(c => c.Id == id);

            if (model.Customer.Accounts == null)
            {
                return(View("NoAccounts"));
            }

            return(View(model.Customer.Accounts));
        }
Example #3
0
        public ActionResult RegisterCustomer(AccountCustomerViewModel _model)
        {
            ViewBag.PageNumber = 1;
            if (ModelState.IsValid)
            {
                using (BuilderDBEntities db = new BuilderDBEntities())
                {
                    var compEmail = db.Companies.FirstOrDefault(x => x.email == _model.email);
                    var compLogin = db.Companies.FirstOrDefault(x => x.login == _model.login);
                    var custEmail = db.Customers.FirstOrDefault(x => x.email == _model.email);
                    var custLogin = db.Customers.FirstOrDefault(x => x.login == _model.login);
                    if ((compEmail == null) && (compLogin == null) && (custEmail == null) && (custLogin == null))
                    {
                        Customer customer = new Customer();
                        customer.name        = _model.name;
                        customer.surname     = _model.surname;
                        customer.login       = _model.login;
                        customer.phoneNumber = _model.phoneNumber;
                        customer.email       = _model.email;
                        customer.password    = Security.sha512encrypt(_model.password);
                        customer.role_id     = 1;
                        customer.isDelete    = false;
                        db.Customers.Add(customer);
                        db.SaveChanges();
                        return(RedirectToAction("Login"));
                    }
                    else if ((compEmail != null) || (custEmail != null))
                    {
                        ModelState.AddModelError("Email", "Użytkownik o podanym emailu już istnieje");
                    }
                    else if ((compLogin != null) || (custLogin != null))
                    {
                        ModelState.AddModelError("Login", "Użytkownik o podanym loginie już istnieje");
                    }
                }
            }

            return(View(_model));
        }
Example #4
0
        public ActionResult LoginCustomer(AccountCustomerViewModel _model)
        {
            using (BuilderDBEntities db = new BuilderDBEntities())
            {
                bool validEmail = db.Customers.Any(x => x.email == _model.email);
                bool validLogin = db.Customers.Any(x => x.login == _model.login);

                if (!(validEmail || validLogin))
                {
                    ModelState.AddModelError("Password", "Niepoprawny login lub hasło");
                    return(View(_model));
                }

                _model.password = Security.sha512encrypt(_model.password);

                Customer customer = db.Customers.FirstOrDefault(u => u.login.Equals(_model.password) && u.password.Equals(_model.password));

                string authId = Guid.NewGuid().ToString();

                Session["AuthID"] = authId;
                var cookie = new HttpCookie("AuthID");
                cookie.Value = authId;
                Response.Cookies.Add(cookie);

                if (customer != null)
                {
                    FormsAuthentication.SetAuthCookie(customer.login, false);
                    var authTicket = new FormsAuthenticationTicket(1, customer.login, DateTime.UtcNow, DateTime.UtcNow.AddMinutes(60), false, "");
                    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
                    authCookie.Expires = DateTime.UtcNow.AddMinutes(60);
                    Response.SetCookie(authCookie);
                    return(RedirectToAction("Home", "Account"));
                }
                return(View(_model));
            }
        }