Ejemplo n.º 1
0
 public ActionResult Activate(long id)
 {
     var isDeleted = locationService.ActivateLocation(id);
     if (isDeleted)
     {
         TempData["Message"] = new MessageViewModel { Message = "Location Enabled Successfully", IsInfo = true };
     }
     else
     {
         TempData["Message"] = new MessageViewModel { Message = "Location Disabled Successfully", IsInfo = true };
     }
     return RedirectToAction("LocationIndex");
 }
Ejemplo n.º 2
0
        public ActionResult AddArea(AreaViewModel model)
        {
            if (model.Area.AreaId == 0)
            {
                model.Area.RecCreatedDate = DateTime.Now;
                model.Area.RecCreatedBy = Session["UserID"].ToString();
            }
            model.Area.RecLastUpdatedBy = Session["UserID"].ToString();
            model.Area.RecLastUpdatedDate = DateTime.Now;

            if (areaService.AddUpdateArea(model.Area.MapFromClientToServer()))
            {
                TempData["Message"] = new MessageViewModel { Message = "Area Added Successfully", IsSaved = true };
            }
            else
            {
                TempData["Message"] = new MessageViewModel { Message = "Something Went wrong", IsError = true };
            }

            if (Request.Form["save"] != null)
                return RedirectToAction("AreaIndex");

            return RedirectToAction("AddArea");
        }
Ejemplo n.º 3
0
 public ActionResult Delete(long id)
 {
     var isDeleted = areaService.DeleteArea(id);
     if (isDeleted)
     {
         TempData["Message"] = new MessageViewModel { Message = "Area Deleted Successfully", IsSaved = true };
     }
     else
     {
         TempData["Message"] = new MessageViewModel { Message = "Something went wrong", IsError = true };
     }
     return RedirectToAction("AreaIndex");
 }
Ejemplo n.º 4
0
        public async Task<ActionResult> SignUp(AspNetUserModel oModel)
        {
            oModel.UserName = oModel.Email;
            Utility oUtility = new Utility();
            oModel.RoleId = Utility.MemberRoleId;
            oModel.RoleName = Utility.MemberRoleName;
            var user = new AspNetUser
            {
                UserName = oModel.UserName,
                Email = oModel.Email,
                Address = oModel.Address,
                Telephone = oModel.Telephone,
                FirstName = oModel.FirstName,
                LastName = oModel.LastName,
                UserComments = string.Empty,
                LockoutEnabled = false
            };

            user.EmailConfirmed = true;
            if (!String.IsNullOrEmpty(oModel.Password))
            {
                var result = await UserManager.CreateAsync(user, oModel.Password);
                if (result.Succeeded)
                {
                    //Setting role
                    var roleManager = HttpContext.GetOwinContext().Get<ApplicationRoleManager>();
                    var roleName = roleManager.FindById(oModel.RoleId).Name;
                    UserManager.AddToRole(user.Id, roleName);

                    //return PreparePayPalPayment(user);


                    // Add User Preferences for Dashboards Widgets

                    TempData["message"] = new MessageViewModel { Message = "Please check your email for Confirmation", IsSaved = true };
                    return RedirectToAction("Index", "Home");
                }

            }


            return View(oModel);

        }
Ejemplo n.º 5
0
        public ActionResult Profile(AspNetUserModel profileViewModel)
        {
            AspNetUser result = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(User.Identity.GetUserId());

            //Updating Data
            try
            {
                result.FirstName = profileViewModel.FirstName;
                result.LastName = profileViewModel.LastName;
                result.Telephone = profileViewModel.Telephone;
                result.Address = profileViewModel.Address;
                var updationResult = UserManager.Update(result);
                updateSessionValues(result);
                TempData["message"] = new MessageViewModel { Message = "Profile has been updated", IsUpdated = true };
            }
            catch (Exception e)
            {
            }
            return RedirectToAction("Profile");
        }
Ejemplo n.º 6
0
 public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var user = await UserManager.FindByNameAsync(model.Email);
     if (user == null)
     {
         // Don't reveal that the user does not exist
         return RedirectToAction("Login", "Account");
     }
     var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);
     if (result.Succeeded)
     {
         TempData["message"] = new MessageViewModel { Message = "Password has been updated.", IsUpdated = true };
         return RedirectToAction("Login", "Account");
     }
     AddErrors(result);
     return View();
 }
Ejemplo n.º 7
0
        public async Task<ActionResult> Subscribe(SignupViewModel signupViewModel)
        {
            // Add new User
            // Check if User already exists
            var usernames = AspNetUserService.GetAllUsers().Select(x => x.UserName);
            if (usernames.Contains(signupViewModel.UserName))
            {
                // it means username is already taken
                TempData["message"] = new MessageViewModel { Message = "", IsError = true };
                return View(signupViewModel);
            }

            var user = new AspNetUser { UserName = signupViewModel.UserName, Email = signupViewModel.Email };
            user.EmailConfirmed = true;
            if (!String.IsNullOrEmpty(signupViewModel.Password))
            {
                var result = await UserManager.CreateAsync(user, signupViewModel.Password);
                if (result.Succeeded)
                {
                    return RedirectToAction("Index", "Home");
                }
            }
            return View(signupViewModel);
        }
Ejemplo n.º 8
0
        public async Task<ActionResult> Create(AspNetUsersViewModel model)
        {
            model.AspNetUserModel.UserName = model.AspNetUserModel.Email;
            #region Update
            if (!string.IsNullOrEmpty(model.AspNetUserModel.Id))
            {
                //Means Update

                // Get role
                var roleName = RoleManager.FindById(model.AspNetUserModel.RoleId).Name;
                AspNetUser userResult = UserManager.FindById(model.AspNetUserModel.Id);
                string userrRoleID = userResult.AspNetRoles.ToList()[0].Id;
                string userRoleName = RoleManager.FindById(userrRoleID).Name;

                // Check if role has been changed
                /************** DISABLING CHANGE ROLE IMPLEMENTATION/ UNCOMMENT TO RUN 
                if (userrRoleID != model.AspNetUserModel.RoleId)
                 {
                     // Update User Role
                     UserManager.RemoveFromRole(model.AspNetUserModel.Id, userRoleName);
                     UserManager.AddToRole(model.AspNetUserModel.Id, roleName);
                     TempData["message"] = new MessageViewModel { Message = "Role has been updated", IsUpdated = true };
                 }************************/
                // Password Reset
                if (!String.IsNullOrEmpty(model.AspNetUserModel.Password))
                {
                    var token = await UserManager.GeneratePasswordResetTokenAsync(model.AspNetUserModel.Id);
                    var resetPwdResults = await UserManager.ResetPasswordAsync(model.AspNetUserModel.Id, token, model.AspNetUserModel.Password);

                    if (resetPwdResults.Succeeded)
                    {
                        var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
                        if (user != null)
                        {
                            await SignInAsync(user, isPersistent: false);
                        }
                        TempData["message"] = new MessageViewModel
                        {
                            //Message = TMD.Web.Resources.HR.Account.UpdatePass,
                            IsUpdated = true
                        };
                    }
                }
                // Get user by UserId to Update User
                AspNetUser userToUpdate = UserManager.FindById(model.AspNetUserModel.Id);
                //if (userToUpdate.Email != model.AspNetUserModel.Email)
                //{

                if (userToUpdate != null)
                {
                    userToUpdate.UpdateUserTo(model.AspNetUserModel);
                }
                var updateUserResult = await UserManager.UpdateAsync(userToUpdate);
                if (updateUserResult.Succeeded)
                {
                    TempData["message"] = new MessageViewModel
                    {
                        Message = "User has been Updated",
                        IsUpdated = true
                    };
                }
                //}

                return RedirectToAction("Users");
            }
            #endregion
            // Add new User
            if (ModelState.IsValid)
            {
                // TODO:Check # of Users that Admin can create
                var user = new AspNetUser
                {
                    UserName = model.AspNetUserModel.UserName,
                    Email = model.AspNetUserModel.Email,
                    Address = model.AspNetUserModel.Address,
                    Telephone = model.AspNetUserModel.Telephone,
                    FirstName = model.AspNetUserModel.FirstName,
                    LastName = model.AspNetUserModel.LastName,
                    LockoutEnabled = false
                };
                user.EmailConfirmed = true;
                if (!String.IsNullOrEmpty(model.AspNetUserModel.Password))
                {
                    var result = await UserManager.CreateAsync(user, model.AspNetUserModel.Password);
                    if (result.Succeeded)
                    {
                        //Setting role
                        var roleManager = HttpContext.GetOwinContext().Get<ApplicationRoleManager>();
                        var roleName = roleManager.FindById(model.AspNetUserModel.RoleId).Name;
                        UserManager.AddToRole(user.Id, roleName);
                        // Add User Preferences for Dashboards Widgets

                        TempData["message"] = new MessageViewModel
                        {
                            Message = "Employee has been created",
                            IsSaved = true
                        };
                        return RedirectToAction("Users");
                    }
                    else
                    {
                        var resultStr = "";
                        if (result.Errors.Count() > 0)
                            resultStr = result.Errors.ToList()[0].ToString();
                        TempData["message"] = new MessageViewModel
                        {
                            Message = resultStr,
                            IsError = true
                        };
                        ViewBag.MessageVM = TempData["message"] as MessageViewModel;
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            model.Roles = HttpContext.GetOwinContext().Get<ApplicationRoleManager>().Roles.ToList();
            //TempData["message"] = new MessageViewModel { Message = TMD.Web.Resources.HR.Account.ChkFields, IsError = true };
            return View(model);
        }
Ejemplo n.º 9
0
        public ActionResult AddLocation(LocationViewModel model)
        {
            if (model.Location.LocationId == 0)
            {
                model.Location.RecCreatedDate = DateTime.Now;
                model.Location.RecCreatedBy = Session["UserID"].ToString();
            }
            model.Location.RecLastUpdatedBy = Session["UserID"].ToString();
            model.Location.RecLastUpdatedDate = DateTime.Now;

            var savedLocationId = locationService.AddUpdateLocations(model.Location.MapFromClientToServer());
            if (savedLocationId > 0)
            {
                TempData["Message"] = new MessageViewModel { Message = "Location Added Successfully", IsSaved = true };
                if (!AddLocationImages(savedLocationId))
                {
                    TempData["Message"] = new MessageViewModel { Message = "Location Added, But Images not saved. All Images Must be less than 1Mb", IsSaved = true };
                }
            }
            else
            {
                TempData["Message"] = new MessageViewModel { Message = "Something Went wrong", IsError = true };
            }

            if (Request.Form["save"] != null)
                return RedirectToAction("LocationIndex");

            return RedirectToAction("AddLocation");
        }