public ActionResult AddNotateToCloset(OutfitNotate outfitNotate) { ClosetOutfit outfit = closetOutfitRepository.Get(outfitNotate.OutfitSelected); if (StringHelper.IsDateTime(outfitNotate.WornDate)) { IFormatProvider formatProvider = new CultureInfo("en-US"); outfit.Notate(outfitNotate.Location, Convert.ToDateTime(outfitNotate.WornDate, formatProvider)); if (outfit.Detail == null) { outfit.Detail = new MaxOutfitDetail(); outfit.Detail.ClosetOutfit = outfit; } if (outfit.Detail.WornDate < Convert.ToDateTime(outfitNotate.WornDate, formatProvider)) { outfit.Detail.WornDate = Convert.ToDateTime(outfitNotate.WornDate, formatProvider); outfit.Detail.Location = outfitNotate.Location; } else { outfitNotate.Location = outfit.Detail.Location; outfitNotate.WornDate = outfit.Detail.WornDate.ToString("MM/dd/yyyy"); } closetOutfitRepository.SaveOrUpdate(outfit); // Update index on notate... using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId)) ses.AddEntry(outfit.ToSearchEngineEntry()); return(Json(new { Success = true, outfitNotate.WornDate, outfitNotate.Location })); } return(Json(new { Success = false })); }
public ActionResult SaveUserOutfit(UserOutfitSelection userOutfitselection) { IList <Garment> garments = new List <Garment>(); ClosetOutfit co; for (int i = 0; i < userOutfitselection.ClosetOutfits.Length; i++) { garments.Add( closetRepository.GetClosetGarment(Convert.ToInt32(userOutfitselection.ClosetOutfits.GetValue(i))) .Garment); } try { co = outfitCreationService.CreateUserOutfit(this.UserId, garments, userOutfitselection.Season, userOutfitselection.PrivacyStatus); } catch (NotValidCombinationException) { return(Json(new { Success = false, Message = "Oops, looks like you have more than one of something in this outfit – please use only one jacket, one pant, etc. to create an outfit." })); } catch (CombinationAlreadyExistsException) { return(Json(new { Success = false, Message = "This combination already exists. Try again!" })); } new OutfitUpdaterServiceClient().MatchOutfitUpdatersForCloset(ClosetId); using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId)) { ses.AddEntry(co.ToSearchEngineEntry()); } return(Json(new { Success = true })); }
public void CanRemoveItemFromIndex() { CreateIndex(1); using (SearchEngineService ses = SearchEngineService.GetByCloset(1)) { int totalEntry = ses.GetTotalIndexedEntryCount(); ses.RemovePost(2); Assert.IsTrue(ses.GetTotalIndexedEntryCount() == totalEntry - 1); } }
public void CanSearchEventTypes() { CreateIndex(1); using (SearchEngineService ses = SearchEngineService.GetByCloset(1)) { SearchParameters sp = new SearchParameters(); sp.EventTypes = new[] { "Formal Affair Evening" }; SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false); Assert.IsTrue(ser.TotalCount > 0); } }
public void CanSearchAllSeasons() { CreateIndex(1); using (SearchEngineService ses = SearchEngineService.GetByCloset(1)) { SearchParameters sp = new SearchParameters(); sp.Seasons = new [] { "winter", "summer", "spring", "fall" }; SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false); Assert.IsTrue(ser.TotalCount == 100, ser.TotalCount.ToString()); } }
public void CanSearchFriendRateRange() { CreateIndex(1); using (SearchEngineService ses = SearchEngineService.GetByCloset(1)) { SearchParameters sp = new SearchParameters(); sp.IsRatedByFriends = true; SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false); Assert.IsTrue(ser.TotalCount == 11, ser.TotalCount.ToString()); Assert.IsTrue(ser.Results.Count() > 0); } }
public void CanSearchByBooleanField() { CreateIndex(1); using (SearchEngineService ses = SearchEngineService.GetByCloset(1)) { SearchParameters sp = new SearchParameters(); sp.CreatedByMe = true; SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false); Assert.IsTrue(ser.TotalCount == 0, ser.TotalCount.ToString()); } }
public void GetIndex() { using (SearchEngineService ses = SearchEngineService.GetByCloset(98)) { SearchParameters sp = new SearchParameters(); sp.Seasons = new[] { "winter", "summer", "spring", "fall" }; SearchEngineResponse ser = ses.Search(sp, 0, 9, "EditorRating", false); Console.WriteLine(ser.TotalCount); foreach (SearchEngineResult res in ser.Results) { Console.WriteLine(res.EntryId); } } }
public static void RunSearch(object closet) { using (SearchEngineService ses = SearchEngineService.GetByCloset(Convert.ToInt32(closet))) { SearchParameters sp = new SearchParameters(); sp.FreeText = ""; sp.IsRatedByMe = false; sp.FlavorId = 2; sp.IsRatedByFriends = true; SearchEngineResponse response = ses.Search(sp, 0, 10, "MyRating", true); Assert.IsTrue(response.TotalCount > 0); Console.WriteLine(response.TotalCount); }; }
public static void CreateIndex(object closet) { using (SearchEngineService ses = SearchEngineService.GetByCloset(Convert.ToInt32(closet))) { IList <SearchEngineEntry> lst = new List <SearchEngineEntry>(); for (int i = ((Convert.ToInt32(closet) - 1) * maxRecordsPerCloset); i < maxRecordsPerCloset * Convert.ToInt32(closet); i++) { SearchEngineEntry see = new SearchEngineEntry(); see.EntryId = i; int amountOfClothes = rnd.Next(10) + 1; see.Categories = GetRandom(categories, amountOfClothes / 2); see.Colors = GetRandom(colors, amountOfClothes); see.Silouhettes = GetRandom(silouhettes, amountOfClothes); see.EventTypes = GetRandom(eventTypes); see.Fabrics = GetRandom(fabrics); see.Seasons = GetRandom(seasons); see.Tags = GetRandom(tags); see.EditorRating = Convert.ToInt32(GetRandom(rating, 1)); see.FriendRating = 0; see.FlavorId = Convert.ToInt32(GetRandom(flavor, 1)); see.CreatedByMe = false; see.MyRating = 0; if (i == 1) { see.MyRating = 5; } if (i <= 10) { see.FriendRating = 3; } lst.Add(see); } ses.AddEntries(lst); } }
public ActionResult RemoveOutfitFromCloset(int outfitSelected) { ClosetOutfit outfit = closetOutfitRepository.Get(outfitSelected); outfit.SendToColdStorage(); closetOutfitRepository.SaveOrUpdate(outfit); if (outfit.Closet.FavoriteOutfit == outfit) { outfit.Closet.ClearFavoriteOutfit(); } closetRepository.SaveOrUpdate(outfit.Closet); using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId)) { ses.RemovePost(outfitSelected); } return(Json(new { Success = true })); }
public void CanUpdateIndex() { CreateIndex(1); using (SearchEngineService ses = SearchEngineService.GetByCloset(1)) { //int totalEntry = ses.GetTotalIndexedEntryCount(); //ses.RemovePost(2); //Assert.IsTrue(ses.GetTotalIndexedEntryCount() == totalEntry - 1); SearchEngineEntry see = new SearchEngineEntry(); see.EntryId = 2; int amountOfClothes = rnd.Next(10) + 1; see.Categories = GetRandom(categories, amountOfClothes / 2); see.Colors = GetRandom(colors, amountOfClothes); see.Silouhettes = GetRandom(silouhettes, amountOfClothes); see.EventTypes = GetRandom(eventTypes); see.Fabrics = GetRandom(fabrics); see.Seasons = GetRandom(seasons); see.Tags = GetRandom(tags); see.CreatedByMe = true; see.EditorRating = Convert.ToInt32(GetRandom(rating, 1)); see.FriendRating = Convert.ToInt32(GetRandom(rating, 1)); see.MyRating = 6; see.FlavorId = Convert.ToInt32(GetRandom(flavor, 1)); ses.AddEntry(see); //Assert.IsTrue(ses.GetTotalIndexedEntryCount() == totalEntry); SearchParameters sp = new SearchParameters(); //sp.CreatedByMe = true; sp.MyRating = 6; SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false); Assert.IsTrue(ser.TotalCount == 1); } }
public ActionResult RateOutfit(OutfitRate outfitRate) { ClosetOutfit closetOutfit = closetOutfitRepository.Get(outfitRate.ClosetOutfitId); if (closetOutfit.Rating == null) { closetOutfit.Rating = new Rating(); } closetOutfit.Rating.Rate(closetOutfit, outfitRate.Rate); ActionResult res = Json(new { Success = true }); if (outfitRate.Rate == 5) { if (closetOutfit.Closet.FavoriteOutfit != null) { closetOutfitRepository.SaveOrUpdate(closetOutfit); res = Json(new { Success = true, ReplaceFavorite = true }); } else { res = SetFavorite(outfitRate); } } if (closetOutfit.Closet.FavoriteOutfit != null && closetOutfit.Closet.FavoriteOutfit.Id == closetOutfit.Id) { res = Json(new { Success = true, RemoveFavorite = true }); } closetOutfitRepository.SaveOrUpdate(closetOutfit); using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId)) ses.AddEntry(closetOutfit.ToSearchEngineEntry()); return(res); }
private IList <ClosetOutfitView> Search(out int totalCount, OutfitSearch outfitSearch, RegisteredUser user) { IList <ClosetOutfitView> result = new List <ClosetOutfitView>(); using (SearchEngineService ses = SearchEngineService.GetByCloset(user.Closet.Id)) { string sortBy = string.Empty; switch (outfitSearch.SortBy) { case "1": sortBy = "EditorRating"; break; case "2": sortBy = "MyRating"; break; case "3": sortBy = "FriendRating"; break; case "4": sortBy = "WornDate"; break; } SearchParameters sp = new SearchParameters(); if (outfitSearch.MyFavorites) { sp.MyRating = 5; } if (!string.IsNullOrEmpty(outfitSearch.Search)) { outfitSearch.Search = outfitSearch.Search.Replace(',', ' '); } if (!string.IsNullOrEmpty(outfitSearch.Color)) { outfitSearch.Color = outfitSearch.Color.Replace(',', ' '); } if (!string.IsNullOrEmpty(outfitSearch.Pattern)) { outfitSearch.Pattern = outfitSearch.Pattern.Replace(',', ' '); } sp.FreeText = string.Format("{0} {1} {2}", outfitSearch.Color, outfitSearch.Pattern, outfitSearch.Search); char[] separator = new char[1]; separator[0] = ' '; if (!string.IsNullOrEmpty(outfitSearch.SeasonName)) { sp.Seasons = outfitSearch.SeasonName.Split(separator, StringSplitOptions.RemoveEmptyEntries); } if (!string.IsNullOrEmpty(outfitSearch.Garment) && outfitSearch.Garment != NOCATEGORY) { sp.FreeText += " " + outfitSearch.Garment; } separator[0] = ','; if (!string.IsNullOrEmpty(outfitSearch.SelectedEvents)) { sp.EventTypes = outfitSearch.SelectedEvents.Split(separator, StringSplitOptions.RemoveEmptyEntries); } if (!string.IsNullOrEmpty(outfitSearch.Trend) && outfitSearch.Trend != NOTREND) { Trend trend = trendRepository.GetByName(outfitSearch.Trend); sp.TrendKeywords = new List <string>(trend.Keywords).ToArray(); } if (outfitSearch.CreatedByMe) { sp.CreatedByMe = true; } if (outfitSearch.IsRatedByMe) { sp.IsRatedByMe = true; } if (outfitSearch.IsRatedByFriends) { sp.IsRatedByFriends = true; } if (outfitSearch.IsUpToDate) { sp.IsUpToDate = true; } if (outfitSearch.SelectedFlavors != null && outfitSearch.SelectedFlavors.Split(separator, StringSplitOptions.RemoveEmptyEntries).Length == 1) { sp.FlavorId = Convert.ToInt32(outfitSearch.SelectedFlavors.Split(separator, StringSplitOptions.RemoveEmptyEntries)[0]); } SearchEngineResponse response = ses.Search( sp, (Convert.ToInt32(outfitSearch.Page) * Convert.ToInt32(outfitSearch.PageSize)) - Convert.ToInt32(outfitSearch.PageSize), Convert.ToInt32(outfitSearch.PageSize), sortBy, true); totalCount = response.TotalCount; List <int> lstIds = new List <int>(); foreach (SearchEngineResult engineResult in response.Results) { lstIds.Add(engineResult.EntryId); } if (lstIds.Count > 0) { result = closetOutfitRepository.Search(lstIds, user.Closet.Id); } } return(result); }
public ActionResult Vote(FriendRatingView view) { if (ModelState.IsValid) { FriendRatingInvitation invitation; // Check if this is a new invitation from an anonymous user if (view.InvitationId == 0) { invitation = new FriendRatingInvitation(); invitation.ClosetOutfit = closetOutfitRepository.Get(view.ClosetOutfitId); invitation.User = invitation.ClosetOutfit.Closet.User; invitation.FriendEmail = "Generated by FaceBook"; invitation.KeyCode = string.Empty; invitation.InvitationSentOn = DateTime.Today; } else { invitation = friendRatingInvitationRepository.Get(view.InvitationId); if (!IsValidInvitation(invitation)) { return(RedirectToAction("Index", "Home")); } } invitation.Rate = view.FriendRating; invitation.FriendRateOn = DateTime.Now; invitation.Message = ""; if (!string.IsNullOrEmpty(view.Comment)) { //invitation.Message = HttpUtility.HtmlEncode(view.Comment); invitation.Message = view.Comment; } ClosetOutfit closetOutfit = closetOutfitRepository.Get(view.ClosetOutfitId); closetOutfit.Rating.Rate(view.FriendRating, invitation); closetOutfitRepository.SaveOrUpdate(closetOutfit); using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId)) ses.AddEntry(closetOutfit.ToSearchEngineEntry()); friendRatingInvitationRepository.SaveOrUpdate(invitation); ConfirmRatingData data = new ConfirmRatingData { Components = closetOutfit.Components, Comments = HttpUtility.HtmlEncode(view.Comment), GarmentsUri = Resources.GetGarmentLargePath(), RatingImg = Resources.GetRatingLargePath() + view.FriendRating + ".jpg", RatingText = Resources.GetRatingText(view.FriendRating) }; messageSenderService.SendWithTemplate("confirmrating", invitation.User, data, invitation.User.EmailAddress); return(RedirectToAction("Thanks")); } ClosetOutfitView cv = closetOutfitRepository.GetByClosetOutfitId(view.ClosetOutfitId); view = LoadViewData(view, cv, 0); return(View(view)); }