public JsonResult Index(Guid?id, int?page, int?start, int?limit) { try { SimpleMembershipProvider provider = (SimpleMembershipProvider)Membership.Provider; // Поиск всех записей var allItems = unitOfWork.CustomerRepository().Get(orderBy: q => q.OrderBy(d => d.Name)); int itemsCount = allItems.Count(); int pageSize = (limit ?? 5); int pageNumber = (page ?? 1); var list = allItems.ToList().ToPagedList(pageNumber, pageSize); List <CustomerWithLogin> listWithLogins = new List <CustomerWithLogin>(); foreach (var item in list) { CustomerWithLogin customerWithLogin = new CustomerWithLogin(); customerWithLogin.Address = item.Address; customerWithLogin.Code = item.Code; customerWithLogin.CustomerId = item.CustomerId; customerWithLogin.Discount = item.Discount; customerWithLogin.Name = item.Name; customerWithLogin.UserId = item.UserId; customerWithLogin.Login = provider.GetUserNameFromId(item.UserId); listWithLogins.Add(customerWithLogin); } return(this.Json(new { success = true, total = itemsCount, data = listWithLogins }, JsonRequestBehavior.AllowGet)); } catch { return(this.Json(new { success = false }, JsonRequestBehavior.AllowGet)); } }
public bool ResetPassword(ResetPasswordParameters parameters) { if (parameters == null) { throw new ClientException("It is not allowed to call this authentication service method with no parameters provided."); } _logger.Trace("ResetPassword"); parameters.Validate(); CheckPasswordStrength(parameters.NewPassword); int userId = WebSecurity.GetUserIdFromPasswordResetToken(parameters.PasswordResetToken); SimpleMembershipProvider provider = (SimpleMembershipProvider)Membership.Provider; string userName = provider.GetUserNameFromId(userId); _logger.Trace(() => "ResetPassword " + userName); bool successfulReset = SafeExecute( () => WebSecurity.ResetPassword(parameters.PasswordResetToken, parameters.NewPassword), "ResetPassword", userName); if (successfulReset && !string.IsNullOrEmpty(userName)) { SafeExecute( // Login does not need to be successful for this function to return true. () => { Login(new LoginParameters { UserName = userName, Password = parameters.NewPassword, PersistCookie = false }); }, "Login after ResetPassword", userName); } return(successfulReset); }
public JsonResult Delete(Guid id) { try { Customer customer = unitOfWork.CustomerRepository().GetByID(id); int userId = customer.UserId; unitOfWork.CustomerRepository().Delete(customer); unitOfWork.Save(); SimpleMembershipProvider membership = (SimpleMembershipProvider)Membership.Provider; string userName = membership.GetUserNameFromId(userId); if (Roles.GetRolesForUser(userName).Count() > 0) { Roles.RemoveUserFromRoles(userName, Roles.GetRolesForUser(userName)); } membership.DeleteAccount(userName); membership.DeleteUser(userName, true); return(this.Json(new { success = true })); } catch { return(this.Json(new { success = false })); } }
public JsonResult Index(Guid?id, int?page, int?start, int?limit) { try { SimpleMembershipProvider provider = (SimpleMembershipProvider)Membership.Provider; var allItems = unitOfWork.OrderRepository().Get(orderBy: q => q.OrderBy(d => d.OrderDate)).Where(x => x.Status != null); int itemsCount = allItems.Count(); int pageSize = (limit ?? 5); int pageNumber = (page ?? 1); var list = allItems.ToList().ToPagedList(pageNumber, pageSize); List <ManagerOrderInfo> managerOrdersList = new List <ManagerOrderInfo>(); // TODO: Нельзя в цикле использовать SQL-запросы foreach (var item in list) { ManagerOrderInfo managerOrderInfo = new ManagerOrderInfo(); managerOrderInfo.OrderId = item.OrderId; managerOrderInfo.OrderDate = item.OrderDate; managerOrderInfo.ShipmentDate = item.ShipmentDate; managerOrderInfo.OrderNumber = item.OrderNumber; managerOrderInfo.Status = item.Status; Customer customer = unitOfWork.CustomerRepository().Get(d => d.CustomerId == item.CustomerId).First(); managerOrderInfo.Login = provider.GetUserNameFromId(customer.UserId); managerOrdersList.Add(managerOrderInfo); } return(this.Json(new { success = true, total = itemsCount, data = managerOrdersList }, JsonRequestBehavior.AllowGet)); } catch { return(this.Json(new { success = false }, JsonRequestBehavior.AllowGet)); } }