// GET: UserMng/Form/:id
 public ActionResult Form(string id)
 {
     Models.UserDetailVM model = null;
     if (id != null)
     {
         var user = this.aspNetUserService.Get(id);
         if (user != null)
         {
             model = new Models.UserDetailVM
             {
                 UserName    = user.UserName,
                 FullName    = user.FullName,
                 isActive    = user.isActive,
                 PhoneNumber = user.PhoneNumber,
                 Email       = user.Email,
                 BrandId     = user.BrandID,
                 Id          = user.Id,
             };
             var userRoles = UserManager.GetRoles(user.Id).ToArray();
             ViewBag.userRoles = userRoles;
             if (userRoles.Length > 0)
             {
                 model.Role = userRoles[0];
             }
         }
     }
     ViewBag.brandList = BrandController.GetBrandList();
     ViewBag.roleList  = UserMngController.GetRoleList();
     return(View(model));
 }
Example #2
0
        // GET: Location/Form/:id
        public ActionResult Form(int?id)
        {
            DateTime aDateTime = DateTime.Now;

            Models.LocationDetailVM model        = null;
            IBrandService           brandService = DependencyUtils.Resolve <IBrandService>();

            if (id != null)
            {
                var location = this.locationService.Get(id);
                if (location != null)
                {
                    model = new Models.LocationDetailVM
                    {
                        BrandId     = location.BrandID,
                        LocationId  = location.LocationID,
                        BrandName   = brandService.GetBrandNameByID(location.BrandID),
                        Province    = location.Province,
                        District    = location.District,
                        Address     = location.Address,
                        Description = location.Description,
                        Time        = aDateTime
                    };
                }
            }
            ViewBag.brandList = BrandController.GetBrandList();
            return(View(model));
        }
        //GET: Brand/Index
        public ActionResult Index()
        {
            var brandVMs = new List <Models.BrandDetailVM>();

            brandVMs              = BrandController.GetBrandList();
            ViewBag.brandList     = brandVMs;
            ViewBag.addSuccess    = Session["ADD_RESULT"] ?? false;
            ViewBag.updateSuccess = Session["UPDATE_RESULT"] ?? false;
            Session.Clear();
            return(View());
        }
Example #4
0
        public async System.Threading.Tasks.Task <ActionResult> Update(Models.BrandUserUpdateVM model)
        {
            if (ModelState.IsValid)
            {
                /*Update custom fields*/
                var user = aspNetUserService
                           .Get(a => a.Id == model.Id)
                           .FirstOrDefault();
                var currUser = Helper.GetCurrentUser();
                if (user != null)
                {
                    user.BrandID  = currUser.BrandID;
                    user.FullName = model.FullName;
                    user.isActive = model.isActive;
                    await this.aspNetUserService.UpdateAsync(user);

                    /*Update user role*/
                    //Remove from other Roles
                    var userRoles = UserManager.GetRoles(user.Id).ToArray();
                    if (userRoles.Length > 0)
                    {
                        UserManager.RemoveFromRole(user.Id, userRoles[0]);
                    }
                    //Add to new Role
                    if (model.Role.CompareTo("System Admin") == 0)
                    {
                        model.Role = "Active User";
                    }
                    UserManager.AddToRoles(user.Id, new string[] { model.Role });
                    Session.Clear();
                    Session["UPDATE_RESULT"] = true;
                    return(new ContentResult
                    {
                        Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "BrandUserMng")),
                        ContentType = "text/html"
                    });
                }
                ;
            }
            // If we got this far, something failed, redisplay form
            ViewBag.brandList = BrandController.GetBrandList();
            ViewBag.roleList  = UserMngController.GetRoleList();
            return(View("Form", model));
        }
Example #5
0
        public async System.Threading.Tasks.Task <ActionResult> Add(Models.BrandUserDetailVM model)
        {
            if (ModelState.IsValid)
            {
                var currUser = Helper.GetCurrentUser();
                var user     = new Wisky.Models.ApplicationUser
                {
                    UserName    = model.UserName,
                    Email       = model.Email,
                    FullName    = model.FullName,
                    PhoneNumber = model.PhoneNumber,
                    BrandId     = currUser.BrandID,
                    isActive    = model.isActive,
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    Session.Clear();
                    Session["ADD_RESULT"] = true;
                    if (model.Role.CompareTo("System Admin") == 0)
                    {
                        model.Role = "Active User";
                    }
                    UserManager.AddToRoles(user.Id, new string[] { model.Role });
                    return(new ContentResult
                    {
                        Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "BrandUserMng")),
                        ContentType = "text/html"
                    });
                }
            }
            // If we got this far, something failed, redisplay form
            ViewBag.brandList = BrandController.GetBrandList();
            ViewBag.roleList  = UserMngController.GetRoleList();
            return(View("Form", model));
        }