コード例 #1
0
        public String AddBookingForMobile(String idParam, String username, String password,
            String date, String time, String duration)
        {
            UserService userService = new UserService();
            int userid = userService.findAnUserByName(username).UserID;
            int pcid = int.Parse(idParam);
            DateTime newDate = DateTime.ParseExact(date + " " + time, "dd/MM/yyyy HH:mm", null);
            int intDuration = int.Parse(duration);

            OrderService orderService = new OrderService();
            OrderStatus orderStatus = orderService.isCanOrder(pcid, newDate, intDuration, userid);
            if (orderStatus.status == OrderStatusCode.FAIL)
            {
                return orderStatus.message;
            }
            Order order = new Order();
            order.PCID = pcid;
            order.UserID = userid;
            order.StartTime = newDate;
            order.Duration = intDuration;
            order.OrderStatus = 0;
            // tru balance
            IRepository<Order> repository = new OrderRepository();
            repository.Add(order);
            return "true";
        }
コード例 #2
0
        public ActionResult edit(int? id)
        {
            if (id == null)
            {
                return RedirectToAction("Index", "User");
            }
            else
            {
                IUserService services = new UserService();
                User user = services.findAnUser(id.Value);
                ViewBag.user = user;
                //IRepository<User> repository = new UserRepository();
                //User user = repository.findById(id.Value);
                //ViewBag.user = user;

                List<Role> roles = services.getRoles();
                //RoleRepository role_repo = new RoleRepository();
                //IEnumerable<Role> roles = role_repo.List;
                ViewBag.roles = roles;

            }
            return View();
        }
コード例 #3
0
        public string editUser()
        {
            //get data from request
            int selectedUserID = Int32.Parse(Request.Params["userID"]);
            double newBalance = Double.Parse(Request.Params["balance"]);
            int newRoleID = Int32.Parse(Request.Params["role"]);
            string selectedRoleName = Request.Params["roleName"];

            UserService services = new UserService();
            if(services.checkIsManage(selectedUserID))
            {
                return "manage";
            }
            else
            {
                User selectedUser = services.findAnUser(selectedUserID);
                selectedUser.Balance = newBalance;
                selectedUser.RoleID = newRoleID;
                if (services.updateUser(selectedUser))
                {
                    return "true";
                }
            }

            return "false";

            //return services.updateUser(selectedUser);

            /*
            //get the old info of the account
            IRepository<User> repository = new UserRepository();
            int n_selectedUserID = int.Parse(selectedUserID);
            User selectedUser = repository.findById(n_selectedUserID);
            int oldRoleID = selectedUser.RoleID;
            string selectedUserName = selectedUser.UserName;

            IRepository<Role> role_repo = new RoleRepository();
            Role roleInfo = new Role();
            //get old roleName
            roleInfo = role_repo.findById(oldRoleID);
            string oldRoleName = roleInfo.RoleName;
            //get new roleName
            roleInfo = role_repo.findById(newRoleID);
            string newRoleName = roleInfo.RoleName;

            //update user in User table
            selectedUser.Balance = newBalance;
            selectedUser.RoleID = newRoleID;
            repository.Update(selectedUser);

            var context = new NetCafeWeb.Models.ApplicationDbContext();
            var UserManager = new UserManager<NetCafeWeb.Models.ApplicationUser>(new UserStore<NetCafeWeb.Models.ApplicationUser>(context));
            //var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));

            //var result = RoleManager.

            //var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<NetCafeWeb.Models.ApplicationUser>(new NetCafeWeb.Models.ApplicationDbContext());
            //var manager = new Microsoft.AspNet.Identity.UserManager<NetCafeWeb.Models.ApplicationUser>(store);

            //update the user in asp user
            //var context = new NetCafeWeb.Models.ApplicationDbContext();
            //var account = new AccountController();
            //delete old role for the current user
            ApplicationUser aspSelectedUser = context.Users.Where(u => u.UserName.Equals((selectedUserName), StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
            //ApplicationUser aspSelectedUser = UserManager.Users.FirstOrDefault(u => u.UserName == selectedUserName);

            //account.UserManager.RemoveFromRoleAsync(aspSelectedUser.Id, oldRoleName);
            UserManager.RemoveFromRole(aspSelectedUser.Id, oldRoleName);

            //add new role for the current user
            //account.UserManager.AddToRoleAsync(aspSelectedUser.Id, newRoleName);
            UserManager.AddToRole(aspSelectedUser.Id, newRoleName);

            return true;
            */
        }
コード例 #4
0
 public ActionResult profile(String username)
 {
     IUserService services = new UserService();
     User user = services.findAnUserByName(username);
     ViewBag.user = user;
     return View();
 }
コード例 #5
0
        public ActionResult Index()
        {
            UserService services = new UserService();
            //list users
            //IRepository<User> repository = new UserRepository();
            //IEnumerable<User> users = repository.List;
            List<User> users = services.getUsers();
            ViewBag.users = users;

            //list role
            //RoleRepository role_repo = new RoleRepository();
            //IEnumerable<Role> roles = role_repo.List;
            List<Role> roles = services.getRoles();
            ViewBag.roles = roles;

            return View();
        }
コード例 #6
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Username, Email = model.Email, Fullname = model.Fullname, IdentifyNumber = model.IdentifyNumber, PhoneNo = model.PhoneNo };
                //UserRepository repository = new UserRepository();
                UserService service = new UserService();
                RoleService role_service = new RoleService();
                User usr = new User();
                usr.Fullname = model.Fullname;
                usr.UserName = model.Username;
                usr.Password = model.Password;
                usr.IdentityNumber = model.IdentifyNumber;
                usr.UserPhoneNumber = model.PhoneNo;
                usr.Balance = 0;
                usr.RoleID = role_service.getRoleIdByRoleName("Member");

                if (service.checkExistedUsername(model.Username))
                {
                    AddErrors(IdentityResult.Failed("This username is existed!"));
                    return View(model);
                }
                else
                {
                    bool isSuccess = service.addUser(usr);
                    if (!isSuccess)
                    {
                        AddErrors(IdentityResult.Failed("Problem occured! Cannot add this user!"));
                    }
                    var result = await UserManager.CreateAsync(user, model.Password);
                    if (result.Succeeded)
                    {
                        //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        await this.UserManager.AddToRoleAsync(user.Id, "Member");
                        
                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        return RedirectToAction("Login", "Account");
                    }
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }