public static void SetCookie(User user, int cookieExpireDate = 30) { var myCookie = new HttpCookie(CookieName); myCookie["UserName"] = user.Lastname; //myCookie["License"] = user.; myCookie.Expires = DateTime.Now.AddDays(cookieExpireDate); HttpContext.Current.Response.Cookies.Add(myCookie); }
public ActionResult Create(Guid? userRoleId, Guid? resellerId) { ViewBag.ReselerId = new SelectList(GetResellers(resellerId), "Id", "FullName"); ViewBag.UserRoleId = new SelectList(GetRoles(userRoleId), "Id", "Name", userRoleId); ViewBag.Id = new SelectList(db.UserPasswords, "UserId", "Password"); ViewBag.CountryId = new SelectList(db.Countries, "Id", "Name"); var model = new User {eId = Utilities.GetRandomSalt(5)}; return View(model); }
public ActionResult Create(User user) { Guid? resellerIdGuid = null; var resellerId = Request["ReselerId"]; if (!String.IsNullOrEmpty(resellerId)) { resellerIdGuid = new Guid(resellerId); } else { ModelState.AddModelError("ReselerId","!"); } if (ModelState.IsValid) { user.Id = Guid.NewGuid(); if (User.IsReseller) { //user.ReselerId = User.Id; //user.UserRoleId = db.UserRoles.FirstOrDefault(row => row.Name == "Klant").Id; } db.Users.Add(user); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { throw ex; } //ClientTools.SendUserRegisteredMail(Session["Language"] as string, user.Id); //return BreadCrum.RedirectToPreviousAction(Session, ControllerName); //return BreadCrum.RedirectToPreviousAction(Session, ControllerName); BreadCrum.RemoveLast(Session); return RedirectToAction("Edit", new {id=user.Id}); } Guid? userRoleIdGuid = null; var userRoleId = Request["userRoleId"]; if (!String.IsNullOrEmpty(userRoleId)) { userRoleIdGuid = new Guid(userRoleId); } ViewBag.ReselerId = new SelectList(GetResellers(resellerIdGuid), "Id", "FullName", user.ReselerId); ViewBag.UserRoleId = new SelectList(GetRoles(userRoleIdGuid), "Id", "Name", user.UserRoleId); ViewBag.Id = new SelectList(db.UserPasswords, "UserId", "Password", user.Id); ViewBag.CountryId = new SelectList(db.Countries, "Id", "Name"); return View(user); }
public ActionResult Credit(User user) { var user1 = db.Users.Find((user.Id)); if (user1 != null) { User.Credit = User.Credit - ((user.Credit??0) - (user1.Credit??0)); user1.Credit = user.Credit; db.SaveChanges(); } return BreadCrum.RedirectToPreviousAction(Session, ControllerName); }
public ActionResult Edit(User user) { if (user.Id == User.Id) { ClearUser(); } var resellerId = Request["ReselerId"]; if (String.IsNullOrEmpty(resellerId)) { ModelState.AddModelError("ReselerId", "!"); } if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); db.Entry(user).State = EntityState.Detached; return BreadCrum.RedirectToPreviousAction(Session, ControllerName); } ViewBag.ReselerId = new SelectList(GetResellers(user.ReselerId), "Id", "FullName", user.ReselerId); ViewBag.UserRoleId = new SelectList(GetRoles(user.UserRoleId), "Id", "Name", user.UserRoleId); ViewBag.Id = new SelectList(db.UserPasswords, "UserId", "Password", user.Id); ViewBag.CountryId = new SelectList(db.Countries, "Id", "Name", user.CountryId); return View(user); }
public ActionResult Register() { var defaultContractId = ReadAppSetting("DefaultContractId"); if (string.IsNullOrWhiteSpace(defaultContractId)) { return RedirectToAction("Index", "Home"); } var contractId = new Guid(defaultContractId); var contract = db.Contracts.SingleOrDefault(row => row.Id.Equals(contractId)); var defaultResellerId = ReadAppSetting("DefaultResellerId"); if (string.IsNullOrWhiteSpace(defaultResellerId)) { return RedirectToAction("Index", "Home"); } var resellerId = new Guid(defaultResellerId); var reseller = db.Users.SingleOrDefault(row => row.Id.Equals(resellerId)); var user = new User(); var userContract = new UserContract(); user.Id = Guid.NewGuid(); user.UserRole = db.UserRoles.SingleOrDefault(row => row.Name.Equals("Klant")); user.ReselerId = resellerId; user.eId = Utilities.GetRandomSalt(5); userContract.Id = Guid.NewGuid(); userContract.eId = Utilities.GetRandomSalt(6); userContract.UserId = user.Id; userContract.User = user; userContract.User.UserRoleId = user.UserRole.Id; userContract.User.UserRole = user.UserRole; userContract.Contract = contract; userContract.ContractId = userContract.Contract.Id; userContract.Actief = true; userContract.StartDate = DateTime.Now; userContract.EndDate = DateTime.Now.AddMonths(1); userContract.Name = userContract.Contract.Name; return View(userContract); }
public static IEnumerable<User> Resellers(bool isBeheerder, User user = null) { using (var te = new Tag4sEntities()) { //te.Connection.Open(); IEnumerable<User> result; if (user != null) { if (user.UserRole.Name == "Klant") { result = te.Users.Where(u => u.Id == user.ReselerId).ToList(); return result; } if (user.UserRole.Name == "Reseller") { result = te.Users.Where(u => u.Id == user.ReselerId).ToList(); return result; } } if (isBeheerder) result = te.Users.Where(u => u.Id == null).ToList(); else result = te.Users.Where(u => u.UserRole.Name.Equals("Beheerder") || u.UserRole.Name.Equals("Reseller")).ToList(); return result; } }
public static IEnumerable<UserRole> UserRoles(bool isBeheerder, User user = null) { using (var te = new Tag4sEntities()) { IEnumerable<UserRole> result; if (user != null) { if (user.UserRole.Name == "Klant") { result = te.UserRoles.Where(u => u.Name.Equals("Klant")).ToList(); return result; } if (user.UserRole.Name == "Reseller") { result = te.UserRoles.Where(u => u.Name.Equals("Klant")).ToList(); return result; } } if (isBeheerder) result = te.UserRoles.Where(u => u.Name.Equals("Beheerder")).ToList(); else result = te.UserRoles.Where(u => !u.Name.Equals("Beheerder")).ToList(); //te.Connection.Close(); return result; } }