public void Update(Warehouse input) { using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(input); dbContext.SaveChanges(); } }
public Brand Update(Brand brand) { using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(brand); dbContext.SaveChanges(); } return(Id(brand.Id)); }
public LocaleOutput Update(Locale locale) { using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(locale, m => m.OwnedCollection(l => l.Localized)); dbContext.SaveChanges(); } return(new LocaleOutput(locale)); }
public HomePageImageOutput Update() { var httpRequest = HttpContext.Current.Request; var formData = httpRequest.Form["image"]; if (formData.IsNullOrEmpty()) { throw new Exception("missing image data"); } var input = JsonConvert.DeserializeObject <HomePageImageInput>(formData); var image = new HomePageImage { Id = input.Id, Width = input.Width, Height = input.Height, NavigateUrl = input.NaviateUrl, Localized = input.Localized.Select(l => new LocalizedHomePageImage { HomePageImageId = input.Id, LanguageCode = l.LanguageCode, Title = l.Title, Description = l.Descrption }).ToList() }; if (httpRequest.Files.Count > 0) { var file = httpRequest.Files[0]; var extension = new System.IO.FileInfo(file.FileName).Extension; var imageUrl = "/UploadImages/" + Guid.NewGuid().ToString() + extension; var imageFile = Image.FromStream(file.InputStream); imageFile.Save(HttpContext.Current.Server.MapPath("~" + imageUrl)); image.ImageUrl = imageUrl; } using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(image, i => i.OwnedCollection(ii => ii.Localized)); dbContext.SaveChanges(); } return(Id(image.Id)); }
public SubCategoryOutput UpdateSub() { var httpRequest = HttpContext.Current.Request; var formData = httpRequest.Form["subcategory"]; if (formData.IsNullOrEmpty()) { throw new Exception("missing subcategory data"); } var input = JsonConvert.DeserializeObject <SubCategoryInput>(formData); var subCategory = new SubCategory { Id = input.Id, ParentId = input.ParentId, ImageUrl = input.ImageUrl, Localized = input.Localized .Select(c => new LocalizedSubCategory { SubCategoryId = input.Id, LanguageCode = c.LanguageCode, Name = c.Name, Description = c.Description }).ToList() }; if (httpRequest.Files.Count > 0) { var image = httpRequest.Files[0]; var url = "/UploadImages/" + Guid.NewGuid().ToString() + new System.IO.FileInfo(image.FileName).Extension; image.SaveAs(HttpContext.Current.Server.MapPath("~" + url)); subCategory.ImageUrl = url; } using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(subCategory, m => m.OwnedCollection(c => c.Localized)); dbContext.SaveChanges(); } return(SubId(subCategory.Id)); }
public virtual ActionResult Save(OrderInput input) { using (var context = new AllureContext()) { var order = context.Set <Order>() .Include(o => o.Details) .AsNoTracking() .SingleOrDefault(o => o.Id == input.Id); if (order == null) { throw new Exception(string.Format("order {0} doesn't exist", input.Id.ToString())); } var ids = input.Details.Select(d => d.ProductId).ToArray(); var products = context.Set <Product>().Where(p => ids.Contains(p.Id)).ToDictionary(p => p.Id); var details = input.Details.Where(d => d.Count > 0).Select(d => new OrderDetail { ProductId = d.ProductId, Count = d.Count, Discount = 0m }); order.WillCheck = input.WillCheck; order.CheckTime = input.WillCheck ? input.CheckTime : null; order.CheckContact = input.CheckContact; order.CheckAddress = input.CheckAddress; order.ReceiverName = input.ReceiverName; order.ReceiverAddress = input.ReceiverAddress; order.ReceiverPostCode = input.ReceiverPostCode; order.ReceiverContact = input.ReceiverContact; order.Details = details.ToList(); order.OriginalRealCharge = order.Details.Sum(d => d.RealCharge); order.RealCharge = order.OriginalRealCharge; order.UpdateTime = DateTime.Now; context.UpdateGraph(order, o => o.OwnedCollection(oo => oo.Details)); context.SaveChanges(); return(Json("ok")); } }
public CategoryOutput Update(CategoryInput input) { var category = new Category { Id = input.Id, Localized = input.Localized .Select(c => new LocalizedCategory { CategoryId = input.Id, LanguageCode = c.LanguageCode, Name = c.Name, Description = c.Description }).ToList() }; using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(category, m => m.OwnedCollection(c => c.Localized)); dbContext.SaveChanges(); } return(Id(category.Id)); }
public UserOutput Update(UpdateUserInput input) { var user = new User { Id = input.UserId, Email = input.Email, Gender = input.Gender, FirstName = input.FirstName, LastName = input.LastName, Telephone = input.Telephone, Mobile = input.Mobile, Company = input.Company, Status = input.Status, Roles = input.Roles.Select(r => new UserRole { UserId = input.UserId, Role = r }).ToList(), Deliveries = input.Deliveries .Select(d => new Delivery { Id = d.Id, UserId = input.UserId, Address = d.Address, Phone = d.Phone, Receiver = d.Receiver, PostCode = d.PostCode }).ToList(), }; using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(user, u => u.OwnedCollection(uu => uu.Roles).OwnedCollection(uu => uu.Deliveries)); dbContext.SaveChanges(); } return(Id(user.Id)); }
public ProductOutput Update() { var httpRequest = HttpContext.Current.Request; var formData = httpRequest.Form["product"]; if (formData.IsNullOrEmpty()) { throw new Exception("missing product data"); } var input = JsonConvert.DeserializeObject <ProductInput>(formData); var product = new Product { Id = input.Id, BrandId = input.BrandId, SubCategoryId = input.SubCategoryId, LocaleId = input.LocaleId, VideoUrl = input.VideoUrl, Images = input.Images.Select(i => new ProductImage { Id = i.Id, ProductId = input.Id, ImageUrl = i.ImageUrl, ThumbnailUrl = i.ThumbnailUrl, Height = i.Height, Width = i.Width }).ToList(), Localized = input.Localized.Select(l => new LocalizedProduct { LanguageCode = l.LanguageCode, Description = l.Descrption }).ToList(), Start = input.Start, End = input.End, Number = input.Number, Price = input.Price, DisplayOrder = input.DisplayOrder, Name = input.Name, RecommendedL = input.RecommendedL, RecommendedS = input.RecommendedS }; for (int i = 0; i < httpRequest.Files.Count; i++) { var file = httpRequest.Files[i]; var extension = new System.IO.FileInfo(file.FileName).Extension; var imageUrl = "/UploadImages/" + Guid.NewGuid().ToString() + extension; var image = Image.FromStream(file.InputStream); image.Save(HttpContext.Current.Server.MapPath("~" + imageUrl)); var thumbnail = image.GetThumbnailImage(150, (int)Math.Floor(image.Height * 150d / image.Width), () => false, IntPtr.Zero); var thumbnailurl = "/UploadImages/" + Guid.NewGuid().ToString() + extension; thumbnail.Save(HttpContext.Current.Server.MapPath("~" + thumbnailurl)); product.Images.Add(new ProductImage { ImageUrl = imageUrl, ThumbnailUrl = thumbnailurl, Height = image.Height, Width = image.Width }); } if (product.Images.All(i => i.IsLargeImage) && input.RecommendedS) { throw new Exception("a small image is expected"); } if (product.Images.All(i => !i.IsLargeImage) && input.RecommendedL) { throw new Exception("a large image is expected"); } using (var dbContext = new AllureContext()) { var origin = dbContext.Set <Product>().AsNoTracking().SingleOrDefault(p => p.Id == product.Id); if (origin == null) { throw new HttpException(404, string.Format("product {0} doesn't exist.", product.Id.ToString())); } product.CreateDate = origin.CreateDate; dbContext.UpdateGraph(product, p => p .OwnedCollection(pp => pp.Localized) .OwnedCollection(pp => pp.Images)); dbContext.SaveChanges(); } return(Id(product.Id)); }