public bool SpaceClearance(UserSpace userSpace, bool isCleared = true, Guid?userGuid = null) { if (userGuid == null && Membership.GetUser() == null) { return(false); } var userName = userGuid != null?Membership.GetUser(userGuid)?.UserName : Membership.GetUser()?.UserName; if (!Roles.GetAllRoles().Contains(userSpace.ToString())) { Roles.CreateRole(userSpace.ToString()); } if (isCleared) { if (!Roles.IsUserInRole(userName, userSpace.ToString())) { Roles.AddUserToRole(userName, userSpace.ToString()); } } else { if (!Roles.IsUserInRole(userName, userSpace.ToString())) { return(true); } if (Enum.GetValues(typeof(UserSpace)) .Cast <object>() .Count(space => Roles.IsUserInRole(userName, space.ToString())) < 2) { throw new InvalidOperationException("USER_MUST_HAVE_AT_LEAST_ONE_SPACE"); } if (userSpace == UserSpace.AdminSpace && Roles.GetUsersInRole(UserSpace.AdminSpace.ToString()).Count() < 2) { throw new InvalidOperationException("SYSTEM_MUST_HAVE_AT_LEAST_ONE_ADMIN"); } Roles.RemoveUserFromRole(userName, userSpace.ToString()); switch (userSpace) { case UserSpace.AdminSpace: foreach (var adminClear in Enum.GetValues(typeof(AdminClearances)).Cast <object>().Where(adminClear => Roles.IsUserInRole(userName, adminClear.ToString()))) { Roles.RemoveUserFromRole(userName, adminClear.ToString()); } break; case UserSpace.TeacherSpace: foreach (var adminClear in Enum.GetValues(typeof(TeacherClearances)).Cast <object>().Where(adminClear => Roles.IsUserInRole(userName, adminClear.ToString()))) { Roles.RemoveUserFromRole(userName, adminClear.ToString()); } break; } } return(true); }
/// <summary> /// Les roles dans ce espace /// </summary> /// <param name="profileGuid"></param> /// <param name="userSpace"></param> /// <returns></returns> public IEnumerable GetUserClearances(Guid profileGuid, UserSpace userSpace) { switch (userSpace) { case UserSpace.AdminSpace: return(EnumsHelper.GetAllValuesAndDescriptions <AdminClearances>().Select(role => new ViewCard { Info1 = role.Key, Info2 = role.Value.ToString(), Info3 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) ? "Blue" : "Red", Bool1 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) })); //case UserSpace.PompisteSpace: // return EnumsHelper.GetAllValuesAndDescriptions<TeacherClearances>().Select(role => // new DataCard // { // Info1 = role.Key, // Info2 = role.Value.ToString(), // Info3 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) ? "Blue" : "Red", // Bool1 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) // }); } return(null); }
internal void Refresh(Guid profileGuid, UserSpace userSpace) { new Task(() => Dispatcher.BeginInvoke(new Action(() => { _profileGuid = profileGuid; _userSpace = userSpace; _ROLES_LIST.ItemsSource = App.Store.Authentication.GetUserClearances(_profileGuid, userSpace); }))).Start(); }
public ActionResult RemoveUserSpace(int Id) { UserSpace userSpace = ORM.UserSpaces.Find(Id); ORM.UserSpaces.Remove(userSpace); ORM.SaveChanges(); return(RedirectToAction("Favorites", "Home")); }
internal void Refresh(Guid profileGuid, UserSpace userSpace) { new Task(() => Dispatcher.BeginInvoke(new Action(() => { _profileGuid =profileGuid; _userSpace =userSpace; _ROLES_LIST.ItemsSource=App.Store.Authentication.GetUserClearances(_profileGuid, userSpace); }))).Start(); }
public List <EtsyItem> GetSavedSpaceFurn(UserSpace thisUserSpace) { List <EtsyItem> userItems = new List <EtsyItem>(); //int count = 0; foreach (string listing in thisUserSpace.Listing.Split(',')) { if (listing != string.Empty) { EtsyItem newItem = new EtsyItem(); newItem = UnSpaceDbController.ConvertEtsyItemDb(listing); userItems.Add(newItem); } } //List<EtsyItem> returnList = new List<EtsyItem>(); //foreach (EtsyItem e in userItems) //{ // EtsyItem newItem = new EtsyItem(); // newItem.Listing_Id = e.Listing_Id; // newItem.Positions.Left = thisUserSpace.Positions.Split(',')[count].Split('|')[0]; // newItem.Positions.Top = thisUserSpace.Positions.Split(',')[count].Split('|')[1]; // count++; // JObject data = EtsyDAL.GetEtsyAPI(e.Listing_Id, "listing"); // if(data["results"][0]["state"].ToString() != "sold_out") // { // newItem.Title = data["results"][0]["title"].ToString(); // newItem.Url = data["results"][0]["url"].ToString(); // newItem.Price = data["results"][0]["price"].ToString(); // newItem.Item_Width = data["results"][0]["item_width"].ToString(); // newItem.Item_Length = data["results"][0]["item_length"].ToString(); // newItem.Item_Height = data["results"][0]["item_height"].ToString(); // newItem.Item_Dimensions_unit = data["results"][0]["item_dimensions_unit"].ToString(); // newItem.Currency_Code = data["results"][0]["currency_code"].ToString(); // JObject imageData = EtsyDAL.GetEtsyAPI(newItem.Listing_Id, "image"); // newItem.ImageThumbUrl = imageData["results"][0]["url_75x75"].ToString(); // newItem.ImageFullUrl = imageData["results"][0]["url_fullxfull"].ToString(); // } // returnList.Add(newItem); // System.Threading.Thread.Sleep(500); //} return(userItems); }
public ActionResult SaveFurn(List <string> Listings, List <string> Left, List <string> Top, string Name = "") { if (TempData["prevPage"] != null) { TempData["prevPage"] = TempData["prevPage"]; } if (TempData["nextPage"] != null) { TempData["nextPage"] = TempData["nextPage"]; } if (TempData["SearchQ"] != null) { TempData["SearchQ"] = TempData["SearchQ"]; } if (TempData["MaxP"] != null) { TempData["MaxP"] = TempData["MaxP"]; } SavePositions(Left, Top); UserSpace userSpace = new UserSpace(); userSpace.UserId = User.Identity.Name; userSpace.Name = Name; if (Name == string.Empty || Name == null) { return(RedirectToAction("Index")); } if (Listings == null) { return(RedirectToAction("Index")); } userSpace.Listing = GenerateListingString(Listings); userSpace.SpaceDimensions = GenerateSpaceDimensions(); userSpace.Positions = GeneratePositionString(Left, Top); TempData["furnList"] = thisSpace.furnList; return(RedirectToAction("SaveUserSpace", "UnSpaceDb", userSpace)); }
// GET: Space public ActionResult Index(string Id) { if (Id != null) { UserSpace userSpace = UnSpaceDbController.GetThisUserSpace(Id); thisSpace.furnList = GetSavedSpaceFurn(userSpace); thisSpace.Id = Id; thisSpace.Name = userSpace.Name; UnravelDimensionsString(userSpace.SpaceDimensions); UnravelPositionsString(userSpace.Positions); } if (TempData["items"] != null) { thisSpace.items = (List <EtsyItem>)TempData["items"]; } if (TempData["prevPage"] != null) { ViewBag.PrevPage = TempData["prevPage"]; TempData["prevPage"] = TempData["prevPage"]; } if (TempData["nextPage"] != null) { ViewBag.NextPage = TempData["nextPage"]; TempData["nextPage"] = TempData["nextPage"]; } if (TempData["SearchQ"] != null) { ViewBag.SearchQ = TempData["SearchQ"]; TempData["SearchQ"] = TempData["SearchQ"]; } if (TempData["MaxP"] != null) { ViewBag.MaxP = TempData["MaxP"]; TempData["MaxP"] = TempData["MaxP"]; } return(View(thisSpace)); }
/// <summary> /// Gets the space ID for a given space name. /// </summary> /// <param name="spacename">The name of the space.</param> /// <returns>The space ID if the space was found or an empty string, otherwise.</returns> public string GetSpaceID(string spacename) { UserSpace space = Array.Find(GetUserSpaces(), x => x.name == spacename); return(space == null ? string.Empty : space.id); }
// GET: UnSpaceDb public ActionResult SaveUserSpace(UserSpace userSpace) { List <EtsyItem> furnList = new List <EtsyItem>(); if (TempData["prevPage"] != null) { TempData["prevPage"] = TempData["prevPage"]; } if (TempData["nextPage"] != null) { TempData["nextPage"] = TempData["nextPage"]; } if (TempData["SearchQ"] != null) { TempData["SearchQ"] = TempData["SearchQ"]; } if (TempData["furnList"] != null) { furnList = (List <EtsyItem>)TempData["furnList"]; } UserSpace result = ORM.UserSpaces.SingleOrDefault(u => u.UserId == userSpace.UserId && u.Name == userSpace.Name); if (result != null) { result.Listing = userSpace.Listing; result.QRCode = userSpace.QRCode; result.Name = userSpace.Name; result.SpaceDimensions = userSpace.SpaceDimensions; result.Positions = userSpace.Positions; try { ORM.SaveChanges(); } catch (DbEntityValidationException e) { string error = e.Message; } } else { ORM.UserSpaces.Add(userSpace); try { ORM.SaveChanges(); } catch (DbEntityValidationException e) { string error = e.Message; } } foreach (EtsyItem e in furnList) { List <EtsyItemDb> res = ORM.EtsyItemDbs.Where(r => r.Listing_Id == e.Listing_Id).ToList(); if (res.Count == 0) { EtsyItemDb dbItem = new EtsyItemDb(); dbItem.Listing_Id = e.Listing_Id; dbItem.Title = e.Title; dbItem.Price = e.Price; dbItem.Currency_Code = e.Currency_Code; dbItem.Item_Length = e.Item_Length; dbItem.Item_Width = e.Item_Width; dbItem.Item_Height = e.Item_Height; dbItem.Item_Dimensions_Unit = e.Item_Dimensions_unit; dbItem.Url = e.Url; dbItem.ImageThumbUrl = e.ImageThumbUrl; dbItem.ImageFullUrl = e.ImageFullUrl; dbItem.Description = e.Description; ORM.EtsyItemDbs.Add(dbItem); try { ORM.SaveChanges(); } catch (DbEntityValidationException err) { string error = err.Message; } } } return(RedirectToAction("Index", "Space")); }
private void ButtonOK_Click(object sender, EventArgs e) { SelectedSpace = ListViewUserSpaces.SelectedItems[0].Tag as UserSpace; DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// Les roles dans ce espace /// </summary> /// <param name="profileGuid"></param> /// <param name="userSpace"></param> /// <returns></returns> public IEnumerable GetUserClearances(Guid profileGuid, UserSpace userSpace) { switch (userSpace) { case UserSpace.AdminSpace: return EnumsHelper.GetAllValuesAndDescriptions<AdminClearances>().Select(role => new ViewCard { Info1 = role.Key, Info2 = role.Value.ToString(), Info3 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) ? "Blue" : "Red", Bool1 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) }); //case UserSpace.PompisteSpace: // return EnumsHelper.GetAllValuesAndDescriptions<TeacherClearances>().Select(role => // new DataCard // { // Info1 = role.Key, // Info2 = role.Value.ToString(), // Info3 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) ? "Blue" : "Red", // Bool1 = Roles.IsUserInRole(Membership.GetUser(profileGuid)?.UserName, role.Value.ToString()) // }); } return null; }
public bool SpaceClearance(UserSpace userSpace, bool isCleared = true, Guid? userGuid = null) { if (userGuid == null && Membership.GetUser() == null) return false; var userName = userGuid != null ? Membership.GetUser(userGuid)?.UserName : Membership.GetUser()?.UserName; if (!Roles.GetAllRoles().Contains(userSpace.ToString())) Roles.CreateRole(userSpace.ToString()); if (isCleared) { if (!Roles.IsUserInRole(userName, userSpace.ToString())) Roles.AddUserToRole(userName, userSpace.ToString()); } else { if (!Roles.IsUserInRole(userName, userSpace.ToString())) return true; if (Enum.GetValues(typeof(UserSpace)) .Cast<object>() .Count(space => Roles.IsUserInRole(userName, space.ToString())) < 2) throw new InvalidOperationException("USER_MUST_HAVE_AT_LEAST_ONE_SPACE"); if (userSpace == UserSpace.AdminSpace && Roles.GetUsersInRole(UserSpace.AdminSpace.ToString()).Count() < 2) throw new InvalidOperationException("SYSTEM_MUST_HAVE_AT_LEAST_ONE_ADMIN"); Roles.RemoveUserFromRole(userName, userSpace.ToString()); switch (userSpace) { case UserSpace.AdminSpace: foreach (var adminClear in Enum.GetValues(typeof(AdminClearances)).Cast<object>().Where(adminClear => Roles.IsUserInRole(userName, adminClear.ToString()))) Roles.RemoveUserFromRole(userName, adminClear.ToString()); break; //case UserSpace.TeacherSpace: // foreach (var adminClear in Enum.GetValues(typeof(TeacherClearances)).Cast<object>().Where(adminClear => Roles.IsUserInRole(userName, adminClear.ToString()))) // Roles.RemoveUserFromRole(userName, adminClear.ToString()); // break; } } return true; }