Пример #1
0
        public ActionResult Delete(int id, string from)
        {
            if (from.Equals("data"))
            {
                var masterData = _context.MasterDatas.SingleOrDefault(p => p.Id == id);

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

                _context.MasterDatas.Remove(masterData);
                _context.SaveChanges();

                string description = "[Master Data] <strong>" + masterData.Name + "</strong> was deleted ";
                ReportsController.AddAuditTrail(UserAction.Delete, description, User.Identity.GetUserId(), Module.Settings);
                return(Json(new { success = true, responseText = description }, JsonRequestBehavior.AllowGet));
            }
            if (from.Equals("detail"))
            {
                var masterDetail = _context.MasterDetails.SingleOrDefault(p => p.Id == id);
                if (masterDetail == null)
                {
                    return(HttpNotFound());
                }

                _context.MasterDetails.Remove(masterDetail);
                _context.SaveChanges();

                string description = "[Master Detail] <strong>" + masterDetail.Name + "</strong> was deleted";
                ReportsController.AddAuditTrail(UserAction.Delete, description, User.Identity.GetUserId(), Module.Settings);
                return(Json(new { success = true, responseText = description }, JsonRequestBehavior.AllowGet));
            }
            return(RedirectToAction("Index", "Settings"));
        }
Пример #2
0
        public ActionResult UpdateStatus(int id, string actionName)
        {
            if (actionName.Equals("data"))
            {
                var masterData = _context.MasterDatas.SingleOrDefault(d => d.Id == id);
                if (masterData != null)
                {
                    string status = masterData.Status == "Active" ? "Inactive" : "Active";
                    masterData.Status = status;
                    _context.SaveChanges();

                    string description = "[Master Data] <strong>" + masterData.Name + "</strong> was set to " + status;
                    ReportsController.AddAuditTrail(UserAction.Update, description, User.Identity.GetUserId(), Module.Settings);
                    return(Json(new { success = true, responseText = description }, JsonRequestBehavior.AllowGet));
                }
            }
            else if (actionName.Equals("detail"))
            {
                var masterDetail = _context.MasterDetails.SingleOrDefault(d => d.Id == id);
                if (masterDetail != null)
                {
                    string status = masterDetail.Status == "Active" ? "Inactive" : "Active";
                    masterDetail.Status = status;
                    _context.SaveChanges();

                    string description = "[Master Detail] <strong>" + masterDetail.Name + "</strong> was set to " + status;
                    ReportsController.AddAuditTrail(UserAction.Update, description, User.Identity.GetUserId(), Module.Settings);
                    return(Json(new { success = true, responseText = description }, JsonRequestBehavior.AllowGet));
                }
            }

            return(RedirectToAction("Index", "Settings"));
        }
Пример #3
0
        public ActionResult UpdateStatus(string id)
        {
            var account = _context.Users.SingleOrDefault(a => a.Id == id);
            var user    = _context.UserProfiles.SingleOrDefault(u => u.Id == account.UserProfileId);

            if (account != null && user != null)
            {
                account.Status = (account.Status == "Active" ? "Inactive" : "Active");
                _context.SaveChanges();
                string fullName = user.FirstName + " " + user.LastName;
                ReportsController.AddAuditTrail(UserAction.Update,
                                                "<strong>" + fullName + "</strong> was set to " + account.Status,
                                                User.Identity.GetUserId(), Module.Users);
                return(Json(new { success = true, responseText = user + " has set to " + account.Status }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { success = false, responseText = "Nothings happen, Try again later." }, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public ActionResult SaveMasterDetail(SettingsViewModel model)
        {
            string description = "";

            if (model.MasterDetailId == 0)
            {
                var duplicate = _context.MasterDetails.FirstOrDefault(m => m.Name.Equals(model.Name, StringComparison.OrdinalIgnoreCase));

                if (duplicate != null)
                {
                    return(Json(new { success = false, responseText = "Master Detail " + model.Name + " already exist" }, JsonRequestBehavior.AllowGet));
                }

                var masterData   = _context.MasterDatas.SingleOrDefault(m => m.Id == model.MasterDataId);
                var masterDetail = new MasterDetail
                {
                    MasterData      = masterData,
                    MasterDataId    = masterData.Id,
                    Name            = model.Name,
                    Description     = model.Description,
                    DateTimeCreated = DateTime.Now,
                    DateTimeUpdated = DateTime.Now,
                    Status          = "Active",
                    Value           = model.Name
                };
                _context.MasterDetails.Add(masterDetail);
                description = "[Master Detail] <strong>" + model.Name + "</strong> has been added";
                ReportsController.AddAuditTrail(UserAction.Create, description, User.Identity.GetUserId(), Module.Settings);
            }
            else
            {
                var mData = _context.MasterDetails.SingleOrDefault(d => d.Id == model.MasterDetailId);
                if (mData != null)
                {
                    mData.Name = model.Name;

                    mData.Description     = model.Description;
                    mData.DateTimeUpdated = DateTime.Now;
                }
                description = "[Master Detail] <strong>" + model.Name + "</strong>'s information has been updated.";
                ReportsController.AddAuditTrail(UserAction.Update, description, User.Identity.GetUserId(), Module.Settings);
            }
            _context.SaveChanges();

            return(Json(new { success = true, responseText = "" }, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        public async Task <ActionResult> ChangePassword(string newPassword, string oldP)
        {
            string id     = User.Identity.GetUserId();
            var    result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), oldP, newPassword);

            if (result.Succeeded)
            {
                var    account  = _context.Users.Include(u => u.UserProfile).FirstOrDefault(p => p.Id == id);
                string fullName = account.UserProfile.FirstName + " " + account.UserProfile.LastName;
                ReportsController.AddAuditTrail(UserAction.Update,
                                                "<strong>" + fullName + "</strong> reset his/her password ",
                                                User.Identity.GetUserId(), Module.Users);

                return(Json(new { success = true, responseText = "Password successfuly Change!" }, JsonRequestBehavior.AllowGet));
            }
            AddErrors(result);
            return(Json(new { success = false, field = "currentpw", responseText = errorMessage }, JsonRequestBehavior.AllowGet));
        }
Пример #6
0
        public ActionResult ResetPassword(string id)
        {
            var account = _context.Users.Include(a => a.UserProfile).SingleOrDefault(m => m.Id == id);


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

            var passwordHasher = new Microsoft.AspNet.Identity.PasswordHasher();

            account.PasswordHash = passwordHasher.HashPassword("password1");
            _context.SaveChanges();

            string fullName = account.UserProfile.FirstName + " " + account.UserProfile.LastName;

            ReportsController.AddAuditTrail(UserAction.Update,
                                            "<strong>" + fullName + "</strong>'s password was reseted ",
                                            User.Identity.GetUserId(), Module.Users);

            return(Json(new { success = true, responseText = "Password successfuly Change!" }, JsonRequestBehavior.AllowGet));
        }
Пример #7
0
        public ActionResult Save(UserProfileViewModel model)
        {
            string role = Request.Form["UserRoles"].ToString();

            if (model.EditProfile.Id == 0 && model.EditAccount.Id == null)
            {
                model.EditProfile.DateCreated = DateTime.Now.ToString("MMM-dd-yyyy hh:mm tt");
                _context.UserProfiles.Add(model.EditProfile);
                _context.SaveChanges();

                var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context));
                var user        = new ApplicationUser
                {
                    UserName      = model.EditAccount.UserName,
                    UserProfileId = model.EditProfile.Id,
                    UserProfile   = model.EditProfile,
                    Email         = model.EditAccount.Email,
                    Status        = "Active",
                    RoleId        = Int32.Parse(role)
                };

                var chkUser = userManager.Create(user, "password1");

                if (chkUser.Succeeded)
                {
                    string fullname = model.EditProfile.FirstName + " " + model.EditProfile.LastName;
                    ReportsController.AddAuditTrail(UserAction.Create,
                                                    "<strong>" + fullname + "</strong> has been added.",
                                                    User.Identity.GetUserId(), Module.Users);
                    return(Json(new { success = true, responseText = fullname + " <small>was added.</small>", data = fullname }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { success = false, responseText = "<small>Looks like we have problem in saving new user. please try again later</small>" }, JsonRequestBehavior.AllowGet));
            }

            var profile = _context.UserProfiles.SingleOrDefault(p => p.Id == model.EditProfile.Id);

            if (profile != null)
            {
                profile.FirstName     = model.EditProfile.FirstName;
                profile.LastName      = model.EditProfile.LastName;
                profile.MiddleName    = model.EditProfile.MiddleName;
                profile.Gender        = model.EditProfile.Gender;
                profile.ContactNo     = model.EditProfile.ContactNo;
                profile.Address       = model.EditProfile.Address;
                profile.CompanyId     = model.EditProfile.CompanyId;
                profile.CompanyName   = model.EditProfile.CompanyName;
                profile.MaritalStatus = model.EditProfile.MaritalStatus;
            }


            var account = _context.Users.SingleOrDefault(a => a.UserProfileId == model.EditProfile.Id);

            if (account != null)
            {
                account.Email    = model.EditAccount.Email;
                account.UserName = model.EditAccount.UserName;
                account.RoleId   = Int32.Parse(role);
            }
            _context.SaveChanges();

            string fullName = model.EditProfile.FirstName + " " + model.EditProfile.LastName;

            ReportsController.AddAuditTrail(UserAction.Update,
                                            "<strong>" + fullName + "</strong>'s information has been updated.",
                                            User.Identity.GetUserId(), Module.Users);
            return(Json(new { success = true, responseText = fullName + " <small>has been Updated.</small>" }, JsonRequestBehavior.AllowGet));
        }