Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "LoginUserId,Name,Mobile,Mail,UserName,Password,OldName,Departament,DepartamentName")] LoginUser loginUser)
        {
            var username = User.Identity.GetUserName();

            if (ModelState.IsValid)
            {
                UserActionsHelper.CreateUser(loginUser.UserName, loginUser.Mail, loginUser.Password, "User");
                loginUser.OldName = loginUser.UserName;

                loginUser.Customer = (from customer in db.CustomerInformation
                                      where customer.Name == username
                                      select customer).FirstOrDefault();

                loginUser.Departament = (from departament in db.Departament
                                         where departament.Name == loginUser.DepartamentName
                                         select departament).FirstOrDefault();

                db.LoginUser.Add(loginUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var listOfDepartamets = (from departament in db.Departament
                                     where departament.Customer.Name == username
                                     select departament).ToList().Select(u => new SelectListItem
            {
                Text  = u.Name,
                Value = u.DepartamentId.ToString()
            });

            ViewBag.ListOfDepartaments = listOfDepartamets;

            return(View(loginUser));
        }
Exemplo n.º 2
0
        public IActionResult Create(CustomerInformation customerInformation)
        {
            if (ModelState.IsValid)
            {
                UserActionsHelper.CreateUser(_serviceProvider, _context, customerInformation.Name, customerInformation.Email, customerInformation.Password, "Customer");
                customerInformation.OldName = customerInformation.Name;
                _context.CustomerInformations.Add(customerInformation);

                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customerInformation));
        }
Exemplo n.º 3
0
        public async System.Threading.Tasks.Task <ActionResult> Create([Bind(Include = "CustomerId,Name,Address,Email,Phone,Password,Comments,IsMunicipalityCustomer,NumberOfSchools,OldName")] CustomerInformation customerInformation)
        {
            if (ModelState.IsValid)
            {
                UserActionsHelper.CreateUser(customerInformation.Name, customerInformation.Email, customerInformation.Password, "Customer");

                customerInformation.OldName = customerInformation.Name;

                db.CustomerInformation.Add(customerInformation);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(customerInformation));
        }
Exemplo n.º 4
0
        public IActionResult CreateUser(LoginUser loginUser)
        {
            var username = User.Identity.Name;

            if (ModelState.IsValid)
            {
                try
                {
                    UserActionsHelper.CreateUser(_serviceProvider, _context, loginUser.UserName, loginUser.Mail, loginUser.Password, "User");
                    loginUser.OldName = loginUser.UserName;

                    loginUser.Customer = (from customer in _context.CustomerInformations
                                          where customer.Name == username
                                          select customer).FirstOrDefault();

                    loginUser.Departament = (from departament in _context.Departaments
                                             where departament.Name == loginUser.DepartamentName
                                             select departament).FirstOrDefault();

                    loginUser.Id = _context.LoginUsers.LastOrDefault() != null?_context.LoginUsers.AsNoTracking().LastOrDefault().Id + 1 : 1;

                    _context.LoginUsers.Add(loginUser);
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    ModelState.AddModelError("FullName", "Query error");
                    return(View(loginUser));
                }
            }

            var listOfDepartamets = (from departament in _context.Departaments
                                     where departament.Customer.Name == username
                                     select departament).ToList().Select(u => new SelectListItem
            {
                Text  = u.Name,
                Value = u.Id.ToString()
            });

            ViewBag.ListOfDepartaments = listOfDepartamets;

            return(View(loginUser));
        }