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()); }