public ActionResult RemoveGarmentFromCloset(int garmentSelected) { MembershipUser mu = Membership.GetUser(); RegisteredUser user = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey)); Closet closet = user.Closet; ClosetGarment garment = closetRepository.GetClosetGarment(garmentSelected); closet.RemoveGarment(garment); closetRepository.SaveOrUpdate(closet); closetRepository.RemoveGarmentFromCloset(garment.Id, closet.Id); return(Json(new { Success = true })); }
private bool ExecuteOutfitGenerator(IList <Garment> addedGarments, bool createRecords) { newGarments = null; flavorCombinations.Clear(); outfits.Clear(); this.createRecords = createRecords; if (addedGarments != null) { newGarments = new HashSet <Garment>(); foreach (Garment g in addedGarments) { newGarments.Add(g); } } lstGarments = (from cg in currentGarments where !OutfitValidationService.IsAccessory(cg) select cg).ToList <Garment>(); logger.DebugFormat("Found {0} garments.", lstGarments.Count); lstAccesories = (from cg in currentGarments where OutfitValidationService.IsAccessory(cg) select cg).ToList <Garment>(); logger.DebugFormat("Found {0} accesories.", lstAccesories.Count); if (lstGarments.Count == 0 || lstAccesories.Count == 0) { return(false); } if (createRecords) { closetRepository.DbContext.BeginTransaction(); this.Closet.StartProcessing(); closetRepository.SaveOrUpdate(this.Closet); closetRepository.DbContext.CommitTransaction(); } bool retVal = ExecuteSet(); if (createRecords) { closetRepository.DbContext.BeginTransaction(); this.Closet.MarkAsProcessed(); closetRepository.SaveOrUpdate(this.Closet); closetRepository.DbContext.CommitTransaction(); } return(retVal); }
private IClosetRepository CreateMockClosetRepository() { IClosetRepository repository = MockRepository.GenerateMock <IClosetRepository>(); repository.Expect(delegate { repository.SaveOrUpdate(null); }).IgnoreArguments(); return(repository); }
public ActionResult RemoveGarmentFromCloset(int garmentSelected) { Closet closet = closetRepository.Get(this.ClosetId); ClosetGarment cg = new List <ClosetGarment>(closet.Garments).Find(e => e.Id.Equals(garmentSelected)); Garment g = cg.Garment; closet.RemoveGarment(cg); closetRepository.SaveOrUpdate(closet); closetRepository.RemoveGarmentFromCloset(closet.Id, g.Id); 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 })); }
public bool RegisterMember(string email, string userName, string firstName, string lastName, string password, UserSize userSize, int membershipUserId, string zipCode, IList <UserFlavor> userFlavors, IList <EventType> eventTypes, IList <Garment> mygarments, IList <Garment> mywishlist, string validateUri, string channel, string invitationCode) { bool mustConfirmMail = true; try { IDictionary <string, object> propertyValues; bool invited = false; email = email.ToLower().Trim(); userName = userName.ToLower().Trim(); basicUserRepository.DbContext.BeginTransaction(); if (!string.IsNullOrEmpty(invitationCode)) { propertyValues = new Dictionary <string, object>(); propertyValues.Add("Code", invitationCode); InvitationCode ic = invitationCodeRepository.FindOne(propertyValues); if (!invitationValidatorService.IsValidCode(ic)) { throw new InvalidInvitationCodeException(); } mustConfirmMail = string.IsNullOrEmpty(ic.EmailAddress); ic.MarkUsed(); invitationCodeRepository.SaveOrUpdate(ic); } RegisteredUser user = new RegisteredUser(); user.UserName = userName; user.FirstName = firstName; user.LastName = lastName; user.EmailAddress = email.ToLower().Trim(); user.Size = userSize; user.PhoneNumber = string.Empty; user.MembershipUserId = membershipUserId; user.RegistrationCode = Guid.NewGuid().ToString(); // Used for email verification purposes. user.ChangeZipCode(zipCode); user.SetFlavors(userFlavors); user.Channel = channel; if (eventTypes != null) { foreach (EventType eventType in eventTypes) { user.AddEventType(eventType); } } // Create Closet Closet closet = new Closet(); closet.User = user; closet.PrivacyLevel = PrivacyLevel.Private; closet.MarkAsProcessed(); if (mygarments != null) { foreach (Garment garment in mygarments) { closet.AddGarment(garment); } } user.Closet = closet; // Check if the user does not exist with that mail propertyValues = new Dictionary <string, object>(); propertyValues.Add("EmailAddress", email); BasicUser bu = basicUserRepository.FindOne(propertyValues); // HACK: We need to change the mail of the invited user to be able to add the new registered user. if (bu != null && bu is InvitedUser) { InvitedUser iu = bu as InvitedUser; iu.EmailAddressReplaced = iu.EmailAddress; iu.EmailAddress += new Random().Next().ToString(); basicUserRepository.SaveOrUpdate(iu); basicUserRepository.DbContext.CommitTransaction(); basicUserRepository.DbContext.BeginTransaction(); closetRepository.SaveOrUpdate(closet); basicUserRepository.SaveOrUpdate(user); propertyValues = new Dictionary <string, object>(); propertyValues.Add("User", bu); IList <Friend> lst = friendRepository.FindAll(propertyValues); if (lst.Count > 0) { foreach (Friend f in lst) { Friend newFriend = new Friend(); newFriend.BasicUser = user; newFriend.User = f.BasicUser; newFriend.Status = FriendStatus.Pending; friendRepository.SaveOrUpdate(newFriend); } } invited = true; } else { closetRepository.SaveOrUpdate(closet); basicUserRepository.SaveOrUpdate(user); } // Create wishlist even if no items been selected for further use. WishList wl = new WishList(); wl.User = user; // Save Wish List if (mywishlist != null && mywishlist.Count > 0) { foreach (Garment wishlist in mywishlist) { wl.AddGarment(wishlist); } } wishListRepository.SaveOrUpdate(wl); // Send Email Confirmation Mail if (mustConfirmMail) { SendValidationCode(user, validateUri); } // Commit Transaction basicUserRepository.DbContext.CommitTransaction(); new FashionAde.Utils.OutfitEngineService.OutfitEngineServiceClient().CreateOutfits(closet.Id); if (invited) { basicUserRepository.MigrateInvited(bu as InvitedUser, user); } } catch { try { basicUserRepository.DbContext.RollbackTransaction(); } catch { } throw; } return(mustConfirmMail); }
public ViewResult Register(UserRegistration userRegistration) { var errors = userRegistration.Validate(); if (errors == null) { IList <UserFlavor> userFlavors = Session["UserFlavorSelected"] as List <UserFlavor>; IList <EventType> eventTypes = Session["EventTypeSelected"] as List <EventType>; IList <Garment> mygarments = Session["MyGarments"] as List <Garment>; IList <Garment> mywishlist = Session["MyWishList"] as List <Garment>; PublicUser user = new PublicUser(); user.EmailAddress = userRegistration.Email; user.ChangeZipCode(userRegistration.ZipCode); user.SetFlavors(userFlavors); user.Size = new UserSize(Convert.ToInt32(userRegistration.UserSize)); //TODO: Get the UserId from ASP.NET Membership MembershipCreateStatus status; MembershipUser mu = Membership.CreateUser(userRegistration.UserName, userRegistration.Password, userRegistration.Email, securityQuestionRepository.Get(Convert.ToInt32(userRegistration.SecurityQuestion)).Description, userRegistration.SecurityAnswer, true, out status); if (status != MembershipCreateStatus.Success) { errors = new ErrorSummary(); errors.RegisterErrorMessage("MembershipUser", status.ToString()); return(RegistrationError(userRegistration, errors.ErrorMessages)); } user.MembershipUserId = Convert.ToInt32(mu.ProviderUserKey); user.FirstName = string.Empty; user.LastName = string.Empty; user.PhoneNumber = string.Empty; if (eventTypes != null) { foreach (EventType eventType in eventTypes) { user.AddEventType(eventType); } } registeredUserRepository.SaveOrUpdate(user); Closet closet = new Closet(); closet.User = user; closet.PrivacyLevel = PrivacyLevel.Private; closetRepository.SaveOrUpdate(closet); if (mygarments != null) { foreach (Garment garment in mygarments) { closet.AddGarment(garment); } closetRepository.SaveOrUpdate(closet); } user.Closet = closet; registeredUserRepository.SaveOrUpdate(user); if (mywishlist != null && mywishlist.Count > 0) { WishList wl = new WishList(); wl.User = user; foreach (Garment wishlist in mywishlist) { wl.AddGarment(wishlist); } wishListRepository.SaveOrUpdate(wl); } closetRepository.GenerateCloset(user); Session.Abandon(); Session["UserRegistration"] = mu; return(View("RegistrationFinish", userRegistration)); } return(RegistrationError(userRegistration, errors.ErrorMessages)); }
public bool ExecuteSet() { bool found = false; IList <Garment> garmentsA = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.A) select g).ToList(); IList <Garment> garmentsC = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.C) select g).ToList(); IList <Garment> garmentsD = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.D) select g).ToList(); IList <Garment> garmentsAii = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.Aii) select g).ToList(); IList <Garment> garmentsAi = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.Ai) select g).ToList(); IList <Garment> garmentsB = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.B) select g).ToList(); IList <Garment> garmentsCD = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.C) || g.Tags.Silouhette.Layers.Contains(LayerCode.D) select g).ToList(); IList <Garment> garmentsBCD = (from g in lstGarments where g.Tags.Silouhette.Layers.Contains(LayerCode.C) || g.Tags.Silouhette.Layers.Contains(LayerCode.D) || g.Tags.Silouhette.Layers.Contains(LayerCode.B) select g).ToList(); // A + B, A+C, A+D IEnumerable <Combination> comb = Combine(2, garmentsA, garmentsBCD, null, null, null); // Ai + Aii IEnumerable <Combination> combAiAii = Combine(2, garmentsAi, garmentsAii, null, null, null); // A+B+C, A+B+D IEnumerable <Combination> combABC_D = Combine(3, garmentsA, garmentsB, garmentsCD, null, null); // A+C+D IEnumerable <Combination> combACD = Combine(3, garmentsA, garmentsC, garmentsD, null, null); // Ai + Aii + B, Ai + Aii + C, Ai + Aii + D IEnumerable <Combination> combAii = Combine(3, garmentsAi, garmentsAii, garmentsBCD, null, null); // A+B+C+D IEnumerable <Combination> combABCD = Combine(4, garmentsA, garmentsB, garmentsC, garmentsD, null); // Ai + Aii + B + C, Ai + Aii + C + D IEnumerable <Combination> combAiAiiBC = Combine(4, garmentsAi, garmentsAii, garmentsB, garmentsC, null); IEnumerable <Combination> combAiAiiCD = Combine(4, garmentsAi, garmentsAii, garmentsC, garmentsD, null); // Ai + Aii + B + C + D IEnumerable <Combination> combAiAiiBCD = Combine(5, garmentsAi, garmentsAii, garmentsB, garmentsC, garmentsD); // Find accesories List <Garment> linqAccesories1 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC1) select g).ToList(); List <Garment> linqAccesories2 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC2) select g).ToList(); List <Garment> linqAccesories3 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC3) select g).ToList(); List <Garment> linqAccesories4 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC4) select g).ToList(); List <Garment> linqAccesories5 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC5) select g).ToList(); List <Garment> linqAccesories6 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC6) select g).ToList(); List <Garment> linqAccesories7 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC7) select g).ToList(); List <Garment> linqAccesories8 = (from g in lstAccesories where g.Tags.Silouhette.Layers.Contains(LayerCode.ACC8) select g).ToList(); accesories1 = Combine(1, linqAccesories1, null, null, null, null); accesories2 = Combine(2, linqAccesories1, linqAccesories2, null, null, null); accesories23 = Combine(2, linqAccesories1, linqAccesories3, null, null, null); accesories24 = Combine(2, linqAccesories1, linqAccesories4, null, null, null); accesories25 = Combine(2, linqAccesories1, linqAccesories5, null, null, null); accesories26 = Combine(2, linqAccesories1, linqAccesories6, null, null, null); accesories27 = Combine(2, linqAccesories1, linqAccesories7, null, null, null); accesories28 = Combine(2, linqAccesories1, linqAccesories8, null, null, null); accesories3 = Combine(3, linqAccesories1, linqAccesories2, linqAccesories3, null, null); accesories4 = Combine(4, linqAccesories1, linqAccesories2, linqAccesories3, linqAccesories4, null); accesories5 = Combine(5, linqAccesories1, linqAccesories2, linqAccesories3, linqAccesories4, linqAccesories5); accesories6 = Combine(6, linqAccesories1, linqAccesories2, linqAccesories3, linqAccesories4, linqAccesories5, linqAccesories6, null, null); accesories7 = Combine(7, linqAccesories1, linqAccesories2, linqAccesories3, linqAccesories4, linqAccesories5, linqAccesories6, linqAccesories7, null); accesories8 = Combine(8, linqAccesories1, linqAccesories2, linqAccesories3, linqAccesories4, linqAccesories5, linqAccesories6, linqAccesories7, linqAccesories8); if (createRecords) { _closetRepository.DbContext.BeginTransaction(); Closet.StartProcessing(); _closetRepository.SaveOrUpdate(Closet); _closetRepository.DbContext.CommitTransaction(); } foreach (FashionFlavor fv in currentFlavors) { logger.DebugFormat("Started Flavor {0}.", fv.Name); currentFlavor = fv; IEnumerable <StyleRule> styleRule = from s in lstStyleRules where s.FashionFlavor.Id == fv.Id select s; currentStyleRule = styleRule.First(); for (int i = currentStyleRule.MinimumLayers; i <= currentStyleRule.MaximumLayers; i++) { bool recordsFound = false; logger.DebugFormat("Started Layers {0}", i); switch (i) { case 2: recordsFound = ExcludeCombinations(currentStyleRule, comb); recordsFound = recordsFound || ExcludeCombinations(currentStyleRule, combAiAii); break; case 3: recordsFound = ExcludeCombinations(currentStyleRule, combABC_D); recordsFound = recordsFound || ExcludeCombinations(currentStyleRule, combACD); recordsFound = recordsFound || ExcludeCombinations(currentStyleRule, combAii); break; case 4: recordsFound = ExcludeCombinations(currentStyleRule, combABCD); recordsFound = recordsFound || ExcludeCombinations(currentStyleRule, combAiAiiBC); recordsFound = recordsFound || ExcludeCombinations(currentStyleRule, combAiAiiCD); break; case 5: recordsFound = ExcludeCombinations(currentStyleRule, combAiAiiBCD); break; } // No need to continue to check. if (!createRecords && recordsFound) { return(recordsFound); } found = found || recordsFound; } } if (createRecords) { _closetRepository.DbContext.BeginTransaction(); if (found && Closet.FavoriteOutfit == null) { logger.DebugFormat("Setting default favorite"); int outfitId = _closetRepository.GetBestEditorRatedClosetOutfitId(Closet.Id); Closet.SetFavoriteOutfit(new ClosetOutfit(outfitId)); } Closet.MarkAsProcessed(); _closetRepository.SaveOrUpdate(Closet); _closetRepository.DbContext.CommitTransaction(); if (found) { logger.DebugFormat("Adding outfit updaters"); _outfitUpdaterService.MatchOutfitUpdatersForCloset(Closet.Id); logger.DebugFormat("Finish adding outfit updaters"); } } return(found); }
public ActionResult UploadFile(FormCollection values) { ArrayList lst = GetFormatedValues(values); RegisteredUser user = this.ProxyLoggedUser; IList <UserGarment> lstFiles = new List <UserGarment>(); List <int> garmentsIds = new List <int>(); userGarmentRepository.DbContext.BeginTransaction(); for (int i = 0; i < Request.Files.Count - 1; i++) { HttpPostedFileBase uploadedFile = Request.Files[i]; if (uploadedFile.ContentLength != 0) { UserGarment ug = (UserGarment)lst[i]; ug.User = user; ug.ImageUri = ""; ug.LinkUri = ""; // Find pregarment IDictionary <string, object> propertyValues = new Dictionary <string, object>(); propertyValues.Add("Silouhette", ug.Tags.Silouhette); propertyValues.Add("PatternType", ug.Tags.Pattern.Type); propertyValues.Add("ColorFamily", ug.Tags.DefaultColor.Family); ug.PreGarment = pregarmentRepository.FindOne(propertyValues); ug.UpdateSeasonCode(); ug.UpdateEventTypeCode(); userGarmentRepository.SaveOrUpdate(ug); FileInfo fi = new FileInfo(uploadedFile.FileName); string fileName = "user_" + ug.Id.ToString() + fi.Extension; string path = ConfigurationManager.AppSettings["Resources_Path"]; string filePath = Path.Combine(Path.Combine(path, @"Garments\UploadedImages\"), fileName); string smallImgPath = Path.Combine(Path.Combine(path, @"Garments\65\"), fileName); string largelImgPath = Path.Combine(Path.Combine(path, @"Garments\95\"), fileName); uploadedFile.SaveAs(filePath); // TODO: Improve borders. ImageHelper.MakeTransparent(filePath); ResizeImage(filePath, largelImgPath, 135, 95, true); //Imagenes Grandes ResizeImage(filePath, smallImgPath, 65, 65, true); //Imagenes Pequeñas ug.ImageUri = fileName; userGarmentRepository.SaveOrUpdate(ug); lstFiles.Add(ug); Closet closet = closetRepository.Get(this.ClosetId); closet.AddGarment(ug); closetRepository.SaveOrUpdate(closet); garmentsIds.Add(ug.Id); } } userGarmentRepository.DbContext.CommitTransaction(); new FashionAde.Utils.OutfitEngineService.OutfitEngineServiceClient().AddOutfits(user.Closet.Id, garmentsIds); ViewData["uploadedFiles"] = lstFiles; return(View()); }