public virtual void SetVisibility(ClosetOutfitVisibility visibility) { if (visibility == ClosetOutfitVisibility.Public) { bool isPublic = true; foreach (Garment g in this.Components) { if (g is UserGarment) { UserGarment ug = (g as UserGarment); if (!(ug.ApprovalStatus == ApprovalStatus.Approved && ug.Visibility == GarmentVisibility.Public)) { isPublic = false; } } } if (!isPublic) { this.visibility = ClosetOutfitVisibility.Private; } } this.visibility = visibility; }
public ActionResult UploadFile(FormCollection values) { MembershipUser mu = Membership.GetUser(); if (mu != null) { ViewData["UserName"] = mu.UserName; } ArrayList lst = GetFormatedValues(values); RegisteredUser user = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey)); IList <UserGarment> lstFiles = new List <UserGarment>(); 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 = ""; userGarmentRepository.SaveOrUpdate(ug); FileInfo fi = new FileInfo(uploadedFile.FileName); string fileName = ug.Id.ToString() + fi.Extension; string filePath = Path.Combine(Server.MapPath("/res/Garments/"), fileName); uploadedFile.SaveAs(filePath); Closet closet = user.Closet; closet.AddGarment(ug); closetRepository.SaveOrUpdate(closet); ug.ImageUri = fileName; userGarmentRepository.SaveOrUpdate(ug); lstFiles.Add(ug); } } ViewData["uploadedFiles"] = lstFiles; return(View()); }
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()); }
private ArrayList GetFormatedValues(FormCollection values) { ArrayList lst = new ArrayList(); UserGarment ug = new UserGarment(); int controlId = int.Parse(((NameValueCollection)(values)).AllKeys[0].Substring( ((NameValueCollection)(values)).AllKeys[0].Length - 1, 1)); foreach (string tag in values) { if (tag == "x" || tag == "y") { continue; } if (int.Parse(tag.Substring(tag.Length - 1)) != controlId) { lst.Add(ug); ug = new UserGarment(); controlId++; } string propName = tag.Substring(0, tag.Length - 1); string propValue = values[tag.ToString()]; if (propValue == "") { continue; } switch (propName) { case "Title": Silouhette s = silouhetteRepository.Get(int.Parse(propValue)); ug.Title = s.Category.Description + " " + s.Description; ug.Tags.Silouhette = s; break; case "Fabric": ug.Tags.Fabric = fabricRepository.Get(int.Parse(propValue)); break; case "PrimaryColor": ug.Tags.Colors.Add(colorRepository.Get(int.Parse(propValue))); break; case "Pattern": ug.Tags.Pattern = patternRepository.Get(int.Parse(propValue)); break; case "Season": ug.Tags.Seasons.Add((Season)int.Parse(propValue)); break; case "EventType": ug.Tags.EventTypes.Add(eventTypeRepository.Get(int.Parse(propValue))); break; case "PrivacyStatus": ug.Visibility = (Convert.ToBoolean(propValue)) ? GarmentVisibility.Private : GarmentVisibility.Public; break; } } lst.Add(ug); return(lst); }
private ArrayList GetFormatedValues(FormCollection values) { ArrayList lst = new ArrayList(); UserGarment ug = new UserGarment(); if (values.Count == 0) { return(lst); } int controlId = int.Parse(((NameValueCollection)(values)).AllKeys[0].Substring( ((NameValueCollection)(values)).AllKeys[0].Length - 1, 1)); string titleSilouhette = string.Empty; string titleCategory = string.Empty; string titleColor = string.Empty; string titlePattern = string.Empty; string titleFabric = string.Empty; foreach (string tag in values) { if (tag == "x" || tag == "y") { continue; } if (int.Parse(tag.Substring(tag.Length - 1)) != controlId) { ug.Title = string.Format("{0} {1} {2} {3} {4}", titleSilouhette, titleColor, titlePattern, titleCategory, titleFabric); lst.Add(ug); ug = new UserGarment(); titleSilouhette = string.Empty; titleCategory = string.Empty; titleColor = string.Empty; titlePattern = string.Empty; titleFabric = string.Empty; controlId++; } string propName = tag.Substring(0, tag.Length - 1); string propValue = values[tag.ToString()]; if (propValue == "") { continue; } switch (propName) { case "Title": Silouhette s = silouhetteRepository.Get(int.Parse(propValue)); titleSilouhette = s.Description; titleCategory = s.Category.Description; ug.Tags.Silouhette = s; break; case "Fabric": Fabric f = fabricRepository.Get(int.Parse(propValue)); ug.Tags.Fabric = f; titleFabric = f.Description; break; case "PrimaryColor": FashionAde.Core.Clothing.Color col = colorRepository.Get(int.Parse(propValue)); ug.Tags.Colors.Add(col); ug.Tags.DefaultColor = col; titleColor = col.Description; break; case "Pattern": Pattern p = patternRepository.Get(int.Parse(propValue)); ug.Tags.Pattern = p; titlePattern = p.Description; break; case "Season": ug.Tags.Seasons.Add((Season)int.Parse(propValue)); break; case "EventType": ug.Tags.EventTypes.Add(eventTypeRepository.Get(int.Parse(propValue))); break; case "PrivacyStatus": ug.SetVisibility((Convert.ToBoolean(propValue)) ? GarmentVisibility.Private : GarmentVisibility.Public); break; } } ug.Title = string.Format("{0} {1} {2} {3} {4}", titleSilouhette, titleColor, titlePattern, titleCategory, titleFabric); if (ug.Title != " ") { lst.Add(ug); } return(lst); }