Exemple #1
0
        /// <summary>
        /// The Details action displays the details of a specific Brand Manager user.
        /// </summary>
        /// <param name="id">Employee Id as a parameter</param>
        /// <returns>Details View</returns>
        // GET: BrandManager/Details/5
        public ActionResult Details(int id)
        {
            // find the user in the database
            var user = UserManager.FindById(id);

            // Check if the user exists
            if (user != null)
            {
                var brandmanager = (BrandManager)user;

                BrandManagerViewModel model = new BrandManagerViewModel()
                {
                    Id              = brandmanager.Id,
                    UserName        = brandmanager.UserName,
                    Email           = brandmanager.Email,
                    FirstName       = brandmanager.FirstName,
                    LastName        = brandmanager.LastName,
                    Telephone       = brandmanager.Telephone,
                    TelExtension    = brandmanager.TelExtension,
                    Mobile          = brandmanager.PhoneNumber,
                    Country         = brandmanager.Country,
                    City            = brandmanager.City,
                    ProductDivision = brandmanager.ProductDivision,
                    Roles           = string.Join(" ", UserManager.GetRoles(id).ToArray())
                };

                return(View(model));
            }
            else
            {
                // Customize the error view: /Views/Shared/Error.cshtml
                return(View("Error"));
            }
        }
Exemple #2
0
        /// <summary>
        /// The Delete action removes a Brand Manager user from the database.
        /// </summary>
        /// <param name="id">Employee Id as a parameter</param>
        /// <returns>Delete View</returns>
        // GET: BrandManager/Delete/5
        public ActionResult Delete(int id)
        {
            var brandmanager = (BrandManager)UserManager.FindById(id);

            if (brandmanager == null)
            {
                return(HttpNotFound());
            }

            BrandManagerViewModel model = new BrandManagerViewModel
            {
                Id              = brandmanager.Id,
                UserName        = brandmanager.UserName,
                Email           = brandmanager.Email,
                FirstName       = brandmanager.FirstName,
                LastName        = brandmanager.LastName,
                Telephone       = brandmanager.Telephone,
                TelExtension    = brandmanager.TelExtension,
                Mobile          = brandmanager.PhoneNumber,
                Country         = brandmanager.Country,
                City            = brandmanager.City,
                ProductDivision = brandmanager.ProductDivision,
                Roles           = string.Join(" ", UserManager.GetRoles(id).ToArray())
            };

            return(View(model));
        }
Exemple #3
0
        public ActionResult Create(BrandManagerViewModel model)
        {
            if (ModelState.IsValid)
            {
                var brandmanager = new BrandManager
                {
                    UserName        = model.UserName,
                    Email           = model.Email,
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    Telephone       = model.Telephone,
                    TelExtension    = model.TelExtension,
                    PhoneNumber     = model.Mobile,
                    Country         = model.Country,
                    City            = model.City,
                    ProductDivision = model.ProductDivision
                };

                var result = UserManager.Create(brandmanager, model.Password);

                if (result.Succeeded)
                {
                    var roleResult = UserManager.AddToRoles(brandmanager.Id, "Brand Manager");

                    if (roleResult.Succeeded)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
            return(View());
        }
Exemple #4
0
        public ActionResult Edit(int id, BrandManagerViewModel model)
        {
            // Exclude Password and ConfirmPassword properties from the model otherwise modelstate is false
            ModelState.Remove("Password");
            ModelState.Remove("ConfirmPassword");

            if (ModelState.IsValid)
            {
                var brandmanager = (BrandManager)UserManager.FindById(id);
                if (brandmanager == null)
                {
                    return(HttpNotFound());
                }

                // Edit the brandmanager info
                brandmanager.UserName        = model.UserName;
                brandmanager.Email           = model.Email;
                brandmanager.FirstName       = model.FirstName;
                brandmanager.LastName        = model.LastName;
                brandmanager.Telephone       = model.Telephone;
                brandmanager.TelExtension    = model.TelExtension;
                brandmanager.PhoneNumber     = model.Mobile;
                brandmanager.Country         = model.Country;
                brandmanager.City            = model.City;
                brandmanager.ProductDivision = model.ProductDivision;

                var userResult = UserManager.Update(brandmanager);

                if (userResult.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }