Esempio n. 1
0
 public void ValidHoodNameTest()
 {
     var noHoodName = new HoodData {Name = ""};
     Assert.AreEqual(false, noHoodName.ValidHood(noHoodName));
     var nullHood = new HoodData();
     Assert.AreEqual(false, nullHood.ValidHood(nullHood));
 }
Esempio n. 2
0
 /// <summary>
 ///     Intializes the text editor.
 /// </summary>
 /// <param name="data">The data.</param>
 private void IntializeEditor(HoodData data)
 {
     this.PostEdit.PostBtn.Click += PostComment_Click;
     if (this.PageContext.IsGuest || (!data.IsPublic &&
                                      data.Users.All(
                                          x =>
                                              x.UserId !=
                                              this.PageContext.PageUserID)))
     {
         this.PostEdit.Visible = false;
     }
 }
Esempio n. 3
0
 /// <summary>
 ///     Constructs the hood object list.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <returns></returns>
 public static List<HoodData> ConstructHoodObjectList(DataSet data)
 {
     Contract.Requires(data != null);
     var hoodList = new List<HoodData>();
     foreach (DataRow r in data.Tables[0].Rows)
     {
         var hoodData = new HoodData
         {
             DateCreated = DateTime.Parse(r["DateCreated"].ToString()),
             Details = r["Details"].ToString(),
             HoodId = Convert.ToInt32(r["HoodID"]),
             IsPublic = Convert.ToBoolean(r["IsPublic"]),
             Name = r["Name"].ToString(),
             Picture = r["Picture"].ToString(),
             Users = new List<HoodUser>()
         };
         var hoodUser = new HoodUser
         {
             UserId = Convert.ToInt32(r["UserID"]),
             IsAdmin = Convert.ToBoolean(r["IsAdmin"])
         };
         //check if hood exists
         var found = hoodList.Any(x => x.HoodId == hoodData.HoodId);
         //if found append user to list
         if (found)
         {
             hoodList.Find(x => x.HoodId == hoodData.HoodId).Users.Add(hoodUser);
         }
             //else add the new hood with that user
         else
         {
             //user id of 0 or 1 is bad, cannot have guests joining hoods
             hoodData.Users.Add(hoodUser);
             hoodList.Add(hoodData);
         }
     }
     return hoodList;
 }
Esempio n. 4
0
 /// <summary>
 ///     Adds the hood after verification has been done.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="userId">The user identifier.</param>
 public void AddHood(HoodData data, int userId)
 {
     Contract.Requires(data != null);
     Contract.Requires(!string.IsNullOrEmpty(data.Name));
     Db.add_hood(data.Name, data.Details, data.Picture, userId, data.IsPublic);
 }
Esempio n. 5
0
 /// <summary>
 ///     Valididates if a user can add the hood
 /// </summary>
 /// <param name="data">The data.</param>
 /// <returns></returns>
 public bool ValidHood(HoodData data)
 {
     Contract.Requires(data != null);
     return !string.IsNullOrEmpty(data.Name) && Db.get_hoodname(data.Name) == null;
 }
 /// <summary>
 ///     Handles the Click event of the HoodCreator control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
 protected void HoodCreator_Click([NotNull] object sender, [NotNull] EventArgs e)
 {
     var baseHoodName = this.BaseHood.Text;
     var totalHoods = this.TotalHoodsCreation.Number;
     var hoodList = this.GetCore<HoodData>();
     if (baseHoodName.IsNotSet() || totalHoods < 1 || !this.HoodPicture.HasFile)
     {
         this.PageContext.AddLoadMessage(this.Text("ADMIN", "TEST_INVALIDPARAMETERS"), MessageTypes.Error);
         return;
     }
     if (this.HoodPicture.HasFile)
     {
         if (this.HoodPicture.PostedFile.ContentType.Contains("image"))
         {
             this.HoodPicture.PostedFile.SaveAs(
                 this.GetService<ResourceProvider>().GetPath(RapResource.HoodPictures, "TestData" + Path.GetFileName(this.HoodPicture.FileName)));
         }
     }
     for (var i = 0; i < totalHoods; i++)
     {
         var newHoodName = string.Format("{0}{1}", baseHoodName, i);
         var newHoodDiscription = this.Text("ADMIN", "TESTDATA_HOODDETAILS");
         var randomPrivacy = new Random();
         var newHoodData = new HoodData
         {
             Name = newHoodName,
             Picture = "TestData" + Path.GetFileName(this.HoodPicture.FileName),
             IsPublic = randomPrivacy.Next(0, 2) == 1,
             Details = newHoodDiscription
         };
         newHoodData.AddHood(newHoodData, this.PageContext.PageUserID);
     }
     var listOfUsers =
         UserMembershipHelper.GetAllUsers()
             .Cast<MembershipUser>()
             .Select(x => UserData.GetUserIdFromDisplayName(x.UserName))
             .ToList();
     var listOfHoods = this.GetCore<HoodData>().GetAllHoods();
     foreach (var hd in listOfHoods)
     {
         foreach (var u in listOfUsers)
         {
             hoodList.AddUserToHood(hd.HoodId, u);
         }
     }
     this.PageContext.AddLoadMessage(this.Text("ADMIN", "TESTDATA_DONE"), MessageTypes.Success);
 }