Esempio 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));
        }
Esempio n. 2
0
        public ActionResult Edit([Bind(Include = "CustomerId,Name,Address,Email,Phone,Password,Comments,IsMunicipalityCustomer,NumberOfSchools,OldName")] CustomerInformation customerInformation)
        {
            if (ModelState.IsValid)
            {
                UserActionsHelper.ChangeUserData(customerInformation.OldName, customerInformation.Name, customerInformation.Email, customerInformation.Password);
                customerInformation.OldName = customerInformation.Name;

                db.Entry(customerInformation).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(customerInformation));
        }
Esempio n. 3
0
        public IActionResult Edit(CustomerInformation customerInformation)
        {
            if (ModelState.IsValid)
            {
                customerInformation.OldName = _context.CustomerInformations.Where(u => u.Id == customerInformation.Id).Select(v => v.Name).FirstOrDefault();
                UserActionsHelper.ChangeUserData(_serviceProvider, _context, customerInformation.OldName, customerInformation.Name, customerInformation.Email, customerInformation.Password);
                customerInformation.OldName = customerInformation.Name;

                _context.Entry(customerInformation).State = EntityState.Modified;
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(customerInformation));
        }
Esempio n. 4
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));
        }
Esempio n. 5
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));
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        public ActionResult Edit([Bind(Include = "LoginUserId,Name,Mobile,Mail,UserName,Password,OldName,Departament,DepartamentName")] LoginUser loginUser)
        {
            var username = User.Identity.GetUserName();

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

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

                try
                {
                    //I admit that it's not legal
                    var sqlCommand = String.Format("update dbo.LoginUsers set Departament_DepartamentId = {0} where LoginUserId = {1}", loginUser.Departament.DepartamentId, loginUser.LoginUserId);
                    db.Database.ExecuteSqlCommand(sqlCommand);
                    db.Entry(loginUser).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    ModelState.AddModelError("FullName", "Query error");
                    return(View(loginUser));
                }
            }
            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));
        }
Esempio n. 8
0
        public IActionResult EditUser(LoginUser loginUser)
        {
            var username = User.Identity.Name;

            if (ModelState.IsValid)
            {
                loginUser.OldName = _context.LoginUsers.Where(u => u.Id == loginUser.Id).Select(v => v.UserName).FirstOrDefault();
                UserActionsHelper.ChangeUserData(_serviceProvider, _context, loginUser.OldName, loginUser.UserName, loginUser.Mail, loginUser.Password);
                loginUser.OldName = loginUser.UserName;

                loginUser.Departament = _context.Departaments.Where(d => d.Name == loginUser.DepartamentName).FirstOrDefault();

                try
                {
                    //I admit that it's not legal
                    var sqlCommand = String.Format("update dbo.LoginUsers set DepartamentId = {0} where Id = {1}", loginUser.Departament.Id, loginUser.Id);
                    _context.Database.ExecuteSqlCommand(sqlCommand);
                    _context.Entry(loginUser).State = EntityState.Modified;
                    _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));
        }