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 RateOutfit(OutfitRate outfitRate) { ClosetOutfit closetOutfit = closetOutfitRepository.Get(outfitRate.ClosetOutfitId); if (closetOutfit.Rating == null) { closetOutfit.Rating = new Rating(); } closetOutfit.Rating.Rate(closetOutfit, outfitRate.Rate); if (outfitRate.Rate == 5) { if (closetOutfit.Closet.FavoriteOutfit != null) { closetOutfitRepository.SaveOrUpdate(closetOutfit); return(Json(new { Success = true, WantFavorite = true })); } return(SetFavorite(outfitRate)); } if (closetOutfit.Closet.FavoriteOutfit != null && closetOutfit.Closet.FavoriteOutfit.Id == closetOutfit.Id) { closetOutfit.Closet.ClearFavoriteOutfit(); } closetOutfitRepository.SaveOrUpdate(closetOutfit); return(Json(new { Success = true, WantFavorite = false })); }
public ActionResult RemoveOutfitFromCloset(int outfitSelected) { ClosetOutfit outfit = closetOutfitRepository.Get(outfitSelected); closetOutfitRepository.DeleteClosetOutfit(outfit); return(Json(new { Success = true })); }
public ActionResult ClearFavorite(int closetoutfitid) { ClosetOutfit closetOutfit = closetOutfitRepository.Get(closetoutfitid); closetOutfit.Closet.ClearFavoriteOutfit(); closetOutfitRepository.SaveOrUpdate(closetOutfit); return(Json(new { Success = true })); }
public ActionResult SetFavorite(OutfitRate outfitRate) { ClosetOutfit closetOutfit = closetOutfitRepository.Get(outfitRate.ClosetOutfitId); closetOutfit.IsFavouriteOutfit = true; closetOutfit.Closet.SetFavoriteOutfit(closetOutfit); closetOutfitRepository.SaveOrUpdate(closetOutfit); return(Json(new { Success = true, WantFavorite = false })); }
public ActionResult AddNotateToCloset(OutfitNotate outfitNotate) { ClosetOutfit outfit = closetOutfitRepository.Get(outfitNotate.OutfitSelected); outfit.Notate(outfitNotate.Location, Convert.ToDateTime(outfitNotate.WornDate)); closetOutfitRepository.SaveOrUpdate(outfit); return(Json(new { Success = true })); }
public ClosetOutfitView(int closetOutfit, float averageFriendRating, float averageUserRating, float averageWearRating, float editorRating, DateTime wornDate, string location, float myRating, int preCombination, int eventTypes) { this.Id = closetOutfit; this.closetOutfit = new ClosetOutfit(closetOutfit); this.averageFriendRating = averageFriendRating; this.averageWearRating = averageWearRating; this.averageUserRating = averageUserRating; this.editorRating = editorRating; this.wornDate = wornDate; this.location = location; this.myRating = myRating; this.preCombination = new PreCombination(preCombination); this.eventTypes = eventTypes; }
public ActionResult SetFavorite(OutfitRate outfitRate) { ClosetOutfit closetOutfit = closetOutfitRepository.Get(outfitRate.ClosetOutfitId); closetRepository.DbContext.BeginTransaction(); Closet c = closetRepository.Get(this.ClosetId); c.SetFavoriteOutfit(closetOutfit); closetRepository.SaveOrUpdate(c); closetRepository.DbContext.CommitTransaction(); string name = closetOutfitRepository.GetByClosetOutfitId(closetOutfit.Id).ShortEventTypes + closetOutfit.Id; return(Json(new { Success = true, SetFavorite = true, Name = name })); }
public ActionResult InviteFriends(InviteFriends inviteFriends) { string[] emails = inviteFriends.FriendsEmails.Split(','); RegisteredUser user = GetUser(); ClosetOutfit co = closetOutfitRepository.Get(Convert.ToInt32(inviteFriends.OutfitId)); SmtpMailing mail = new SmtpMailing(); foreach (string email in emails) { string subject = user.FullName + " want that you rate her outfit"; string body = ""; foreach (Garment garment in co.Components) { body += "<img src='" + inviteFriends.SiteURL + "/" + Resources.GetGarmentPath(garment) + "' alt='" + garment.Title + "' /> "; } string key = Guid.NewGuid().ToString(); body += "<br /><br />Rate it NOW <a href='" + inviteFriends.SiteURL + "/rating/index/" + key + "/default.aspx' style='color: #F38333;' >here</a>!"; FriendRatingInvitation invitation = new FriendRatingInvitation(); invitation.FriendEmail = email; invitation.InvitationSentOn = DateTime.Now; invitation.FriendRateOn = invitation.InvitationSentOn; invitation.KeyCode = key; invitation.Message = inviteFriends.Message; invitation.User = user; invitation.ClosetOutfit = co; friendRatingInvitationRepository.SaveOrUpdate(invitation); mail.SendMail(email, "Rate my outfit", subject, body, false); } if (inviteFriends.SendMe) { string subject = user.FullName + " want that you rate her outfit"; string body = ""; foreach (Garment garment in co.Components) { body += "<img src='" + inviteFriends.SiteURL + "/" + Resources.GetGarmentPath(garment) + "' alt='" + garment.Title + "' /> "; } body += "<br /><br />Rate it NOW <span style='color: #F38333;' >here</span>! <span style='font-size=10px;'>(only your friends get the rating link)</span>"; mail.SendMail(user.EmailAddress, "Rate my outfit", subject, body, false); } return(Json(new { Success = true })); }
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 })); }
/// <summary> /// Validates if the user can access the Outfit /// </summary> /// <param name="bu"></param> /// <param name="co"></param> /// <returns></returns> public static bool CanViewClosetOutfit(BasicUser bu, ClosetOutfit co) { Closet c = co.Closet; if (bu != null && c.User.Id == bu.Id) { return(true); } bool isFriendOrFull = CanViewCloset(bu, c); if (isFriendOrFull) { return(true); } if (c.PrivacyLevel == PrivacyLevel.FavoriteOutfit && co.Id == co.Closet.FavoriteOutfit.Id) { return(true); } return(false); }
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); }
public ActionResult Index(int friendsrating, string Comments, Guid Key) { FriendRatingInvitation invitation = friendRatingInvitationRepository.GetByKey(Key.ToString()); invitation.Rate = friendsrating; invitation.FriendRateOn = DateTime.Now; invitation.Message = ""; if (!string.IsNullOrEmpty(Comments)) { invitation.Message = Comments; } ClosetOutfit closetOutfit = invitation.ClosetOutfit; if (closetOutfit.Rating == null) { closetOutfit.Rating = new Rating(); } closetOutfit.Rating.Rate(friendsrating, invitation); friendRatingInvitationRepository.SaveOrUpdate(invitation); closetOutfitRepository.SaveOrUpdate(closetOutfit); return(View("Thanks", invitation)); }
public void CopyOutfitFromOtherUserCloset(int closetOutfitId, int userId) { ClosetOutfit co = closetOutfitRepository.Get(closetOutfitId); // Make sure this closet is public if (co.Closet.PrivacyLevel != PrivacyLevel.FullCloset && !(co.Closet.FavoriteOutfit == co && co.Closet.PrivacyLevel == PrivacyLevel.FavoriteOutfit)) { throw new Exception("You can not access this outfit."); } ClosetOutfit copiedOutfit = co.Clone() as ClosetOutfit; copiedOutfit.CreatedFrom = co; BasicUser bu = basicUserRepository.Get(userId); copiedOutfit.FashionFlavor = bu.GetPreferredFlavor(); copiedOutfit.SetEventTypes(bu as RegisteredUser); copiedOutfit.Closet = (bu as RegisteredUser).Closet; copiedOutfit.User = bu as RegisteredUser; closetOutfitRepository.SaveOrUpdate(copiedOutfit); }
/// <summary> /// Creates a new closet outfit in the system related with the current user. /// </summary> /// <param name="userId">User</param> /// <param name="garments">List of Garments</param> /// <param name="season">Season</param> /// <param name="visibility">Visibility</param> /// <exception cref="NotValidCombinationException">When a combination is not valid.</exception> public void CreateUserOutfit(int userId, IList <Garment> garments, Season season, ClosetOutfitVisibility visibility) { if (!OutfitValidationService.IsValidCombination(garments)) { throw new NotValidCombinationException(); } ClosetOutfit uo = new ClosetOutfit(); // HACK: We need the garments saved with 0 in the non filled fields to make sure we have no duplicates. Garment hack = garmentRepository.Get(0); foreach (Garment g in garments) { uo.AddComponent(g, hack); } uo.Rating.CalculateEditorRating(uo.Components); BasicUser bu = basicUserRepository.Get(userId); FashionFlavor ff = bu.GetPreferredFlavor(); uo.FashionFlavor = ff; uo.Closet = (bu as RegisteredUser).Closet; uo.SetSeason(season); uo.SetEventTypes(bu as RegisteredUser); uo.SetVisibility(visibility); //Agregar PreCombination PreCombination pc = preCombinationRepository.GetByGarments(uo.RetrieveCombinableComponents().ToList <Garment>(), ff); if (pc == null) { pc = new PreCombination(); pc.FashionFlavor = ff; for (int j = 0; j < garments.Count; j++) { Garment g = garments[j]; if (!OutfitValidationService.IsAccessory(g)) { pc.AddPreGarment(garments[j]); } } } uo.PreCombination = pc; uo.User = bu as RegisteredUser; if (!uo.IsValid()) { throw new NotValidCombinationException(); } closetOutfitRepository.DbContext.BeginTransaction(); // REVIEW: This may lead to orphaned records, given we cannot change the autonumeric for now because of the combination process. // TODO: Is better to check first if the Closet Outfit combination already exists and then proceed. preCombinationRepository.SaveOrUpdate(pc); try { closetOutfitRepository.SaveOrUpdate(uo); closetOutfitRepository.DbContext.BeginTransaction(); } catch { closetOutfitRepository.DbContext.RollbackTransaction(); throw new CombinationAlreadyExistsException(); } }
public JsonResult InviteFriends(InviteFriends inviteFriends) { string[] contacts = inviteFriends.FriendsEmails.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); RegisteredUser user = registeredUserRepository.Get(this.UserId); ClosetOutfit co = closetOutfitRepository.Get(Convert.ToInt32(inviteFriends.OutfitId)); foreach (string contact in contacts) { if (string.IsNullOrEmpty(contact) || contact == " ") { continue; } string email = contact; if (contact.IndexOf("[") != -1 && contact.IndexOf("]") != -1) { email = contact.Split('[')[1].Split(']')[0]; } string key = Guid.NewGuid().ToString(); List <Garment> lst = new List <Garment>(); foreach (Garment garment in co.Components) { if (garment.Id != 0) { lst.Add(garment); } } EmailData data = new EmailData { Components = lst, KeyCode = key, Comments = HttpUtility.HtmlEncode(inviteFriends.Message), InvitationLink = "/Outfit/Rating/VoteFromInvitation/" + key + "/default.aspx", GarmentsUri = Resources.GetGarmentLargePath(), OutfitUpdater = outfitUpdaterRepository.GetRandomOutfitUpdaterFor(co.PreCombination) }; if (data.OutfitUpdater == null) { data.OutfitUpdater = new OutfitUpdater(); data.OutfitUpdater.BuyUrl = string.Empty; data.OutfitUpdater.ImageUrl = string.Empty; data.OutfitUpdater.Name = string.Empty; data.OutfitUpdater.Partner = new Partner(string.Empty, string.Empty); } data.OutfitUpdaterPrice = Convert.ToDecimal(data.OutfitUpdater.Price).ToString("$#,##0.00"); messageSenderService.SendWithTemplate("invite2rate", user, data, email); FriendRatingInvitation invitation = new FriendRatingInvitation(); invitation.FriendEmail = email; invitation.InvitationSentOn = DateTime.Now; invitation.FriendRateOn = invitation.InvitationSentOn; invitation.KeyCode = key; invitation.Message = inviteFriends.Message; invitation.User = user; invitation.ClosetOutfit = co; friendRatingInvitationRepository.DbContext.BeginTransaction(); friendRatingInvitationRepository.SaveOrUpdate(invitation); friendRatingInvitationRepository.DbContext.CommitTransaction(); } if (inviteFriends.SendMe) { EmailCopyData data = new EmailCopyData { Components = co.Components, Comments = HttpUtility.HtmlEncode(inviteFriends.Message), GarmentsUri = Resources.GetGarmentLargePath(), OutfitUpdater = outfitUpdaterRepository.GetRandomOutfitUpdaterFor(co.PreCombination) }; data.OutfitUpdaterPrice = Convert.ToDecimal(data.OutfitUpdater.Price).ToString("$#,##0.00"); messageSenderService.SendWithTemplate("copyinvite2rate", user, data, user.EmailAddress); } TrackingHelper.Save("MyOutfitsController", "InviteFriends", Guid.NewGuid().ToString(), "noIp", UserId.ToString(), "noChannel", null, string.Empty); return(Json(new { Success = true })); }
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)); }
public static SearchEngineEntry ToSearchEngineEntry(this ClosetOutfit closetOutfit) { SearchEngineEntry see = new SearchEngineEntry(); see.EntryId = closetOutfit.Id; var categories = new HashSet <string>(); var colors = new HashSet <string>(); var silouhettes = new HashSet <string>(); var eventtypes = new HashSet <string>(); var fabrics = new HashSet <string>(); var seasons = new HashSet <string>(); var keywords = new HashSet <string>(); foreach (Garment g in closetOutfit.Components) { categories.Add(g.Tags.Category.Description); colors.Add(g.Tags.DefaultColor.Description); silouhettes.Add(g.Tags.Silouhette.Description); fabrics.Add(g.Tags.Fabric.Description); if (!string.IsNullOrEmpty(g.Tags.Silouhette.Keywords)) { foreach (string keyword in g.Tags.Silouhette.Keywords.Split(',')) { keywords.Add(keyword.Trim()); } } foreach (EventType ev in g.Tags.EventTypes) { eventtypes.Add(ev.ShortName); } foreach (Season s in g.Tags.Seasons) { seasons.Add(s.ToString()); } } see.CreatedByMe = closetOutfit.User != null; see.EditorRating = Convert.ToInt32(closetOutfit.Rating.EditorRating); see.FriendRating = Convert.ToInt32(Math.Round(closetOutfit.Rating.FriendRatingAverage)); see.MyRating = Convert.ToInt32(closetOutfit.Rating.MyRating); see.FlavorId = closetOutfit.FashionFlavor.Id; if (closetOutfit.Detail != null) { // Mark as up to date, save last worndate and add all locations to the keywords. see.IsUpToDate = true; see.LastWornDate = closetOutfit.Detail.WornDate; foreach (OutfitDetails od in closetOutfit.Details) { keywords.Add(od.Location); } } see.Categories = string.Join(" ", categories.ToArray()); see.Silouhettes = string.Join(" ", silouhettes.ToArray()); see.Colors = string.Join(" ", colors.ToArray()); see.EventTypes = string.Join(" ", eventtypes.ToArray()); see.Fabrics = string.Join(" ", fabrics.ToArray()); see.Seasons = string.Join(" ", seasons.ToArray()); see.Tags = string.Join(" ", keywords.ToArray()); return(see); }