/// <summary> /// Actualiza los UserFlavors del usuario por los nuevos seleccionados. /// </summary> /// <param name="Flavor1Weight">Peso del primer Fashion Flavor seleccionado.</param> /// <param name="Flavor2Weight">Peso del segudno Fashion Falvor determinado.</param> /// <param name="values">Coleccion de objetos del formulario</param> /// <returns>Actualiza los flavors seleccionados y redirecciona a la Home.</returns> public ActionResult UpdateUserFlavors(string Flavor1Weight, string Flavor2Weight, string submit) { bool previous = (submit != null && submit.ToLower() == "previous"); if (previous) { return(RedirectToAction("Index", "FlavorSelect")); } IList <FashionFlavor> flavors = ClosetState.Flavors; IList <UserFlavor> userFlavors = new List <UserFlavor>(); if (flavors != null) { if (!string.IsNullOrEmpty(Flavor1Weight)) { userFlavors.Add(new UserFlavor(flavors[0], Convert.ToDecimal(Flavor1Weight))); } if (!string.IsNullOrEmpty(Flavor2Weight)) { userFlavors.Add(new UserFlavor(flavors[1], Convert.ToDecimal(Flavor2Weight))); } } RegisteredUser user = registeredUserRepository.Get(this.UserId); List <int> flavorsIds = new List <int>(); List <int> myGarmentsIds = new List <int>(); foreach (FashionFlavor ff in flavors) { flavorsIds.Add(ff.Id); } IList <ClosetGarment> closetGarments = closetRepository.GetGarmentsForUser(user); foreach (ClosetGarment closetGarment in closetGarments) { myGarmentsIds.Add(closetGarment.Garment.Id); } if (!new OutfitEngineServiceClient().HasValidCombinations(myGarmentsIds, flavorsIds)) { return(RedirectToAction("FlavorChangeResult", "FlavorSelect", new { flavorsChanged = false })); } user.SetFlavors(userFlavors); //Update UserFlavors registeredUserRepository.DbContext.BeginTransaction(); registeredUserRepository.SaveOrUpdate(user); registeredUserRepository.DbContext.CommitTransaction(); new OutfitEngineServiceClient().CreateOutfits(user.Closet.Id); UserDataHelper.LoadFromDatabase(); return(RedirectToAction("FlavorChangeResult", "FlavorSelect", new { flavorsChanged = true })); }
private void GetGarmentsListData(RegisteredUser user, GarmentsListData gld) { ViewData["UserName"] = User.Identity.Name; ViewData["styleAlerts"] = contentService.GetRandomStyleAlerts(1); gld.ForEdit = true; gld.Controller = "GarmentSelector"; gld.Action = "GoToMyGarments"; gld.EventTypes = user.EventTypes; foreach (ClosetGarment closetGarment in closetRepository.GetGarmentsForUser(user)) { gld.MyGarmentsIds += closetGarment.Garment.Id + ","; gld.MyGarments.Add(closetGarment); } if (!string.IsNullOrEmpty(gld.MyGarmentsIds)) { gld.MyGarmentsIds = gld.MyGarmentsIds.TrimEnd(','); } WishList wl = wishListRepository.GetForUser(user); if (wl != null) { foreach (WishGarment wishGarment in wl.Garments) { gld.MyWishGarmentsIds += wishGarment.Garment.Id + ","; gld.MyWishGarments.Add(wishGarment); } if (!string.IsNullOrEmpty(gld.MyWishGarmentsIds) && gld.MyWishGarmentsIds.Length > 0) { gld.MyWishGarmentsIds = gld.MyWishGarmentsIds.TrimEnd(','); } } if (!string.IsNullOrEmpty(gld.NewGarmentsIds)) { List <int> newGarmentsIds = new List <int>(); foreach (string id in gld.NewGarmentsIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if (!string.IsNullOrEmpty(id) && id != " ") { newGarmentsIds.Add(Convert.ToInt32(id)); } } gld.NewGarments = garmentRepository.GetByIds(newGarmentsIds); } if (!string.IsNullOrEmpty(gld.NewWishGarmentsIds)) { List <int> newWishGarmentsIds = new List <int>(); foreach (string id in gld.NewWishGarmentsIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if (!string.IsNullOrEmpty(id) && id != " ") { newWishGarmentsIds.Add(Convert.ToInt32(id)); } } gld.NewWishGarments = garmentRepository.GetByIds(newWishGarmentsIds); } //if (gld.FashionFlavors != null) { #region Fix For Categories Order List <Silouhette> silouhettes = silouhetteRepository.ListEnabled() as List <Silouhette>; List <Silouhette> temp = new List <Silouhette>(); temp.AddRange(silouhettes.FindAll(x => x.Category.Id < 10)); temp.AddRange(silouhettes.FindAll(x => x.Category.Id.Equals(12))); temp.AddRange(silouhettes.FindAll(x => x.Category.Id > 9 && x.Category.Id != 12)); gld.Silouhettes = temp; #endregion if (gld.Silouhettes != null) { gld.Fabrics = fabricRepository.GetForSilouhette(gld.Silouhettes[0], gld.EventTypes); gld.FabricId = gld.Fabrics.FirstOrDefault().Id; gld.SilouhetteId = gld.Silouhettes[0].Id; Pattern solid = patternRepository.GetSolid(); gld.Garments = garmentRepository.GetBySelection(gld.Silouhettes[0], gld.Fabrics.FirstOrDefault(), solid, gld.EventTypes, gld.MyGarments, gld.MyWishGarments); gld.PatternId = solid.Id; gld.Patterns = gld.Silouhettes[0].AvailablePatterns; } } //IList<FashionFlavor> flavors = fashionFlavorRepository.GetAll(); //foreach (FashionFlavor flavor in flavors) // if(!gld.FashionFlavors.Exists(delegate(FashionFlavor record) { if (record.Id == flavor.Id) { return true; } return false; })) // gld.FashionFlavorsAlternative.Add(flavor); }