void ReleaseDesignerOutlets() { if (AvailableQuantity != null) { AvailableQuantity.Dispose(); AvailableQuantity = null; } if (ItemDescription != null) { ItemDescription.Dispose(); ItemDescription = null; } if (ItemImage != null) { ItemImage.Dispose(); ItemImage = null; } if (ItemTitle != null) { ItemTitle.Dispose(); ItemTitle = null; } if (UpdateButton != null) { UpdateButton.Dispose(); UpdateButton = null; } }
public override int GetHashCode() { int hash = 1; if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (Id.Length != 0) { hash ^= Id.GetHashCode(); } if (Type != global::Google.Cloud.Retail.V2.Product.Types.Type.Unspecified) { hash ^= Type.GetHashCode(); } if (PrimaryProductId.Length != 0) { hash ^= PrimaryProductId.GetHashCode(); } hash ^= categories_.GetHashCode(); if (Title.Length != 0) { hash ^= Title.GetHashCode(); } if (Description.Length != 0) { hash ^= Description.GetHashCode(); } hash ^= Attributes.GetHashCode(); hash ^= tags_.GetHashCode(); if (priceInfo_ != null) { hash ^= PriceInfo.GetHashCode(); } if (availableTime_ != null) { hash ^= AvailableTime.GetHashCode(); } if (Availability != global::Google.Cloud.Retail.V2.Product.Types.Availability.Unspecified) { hash ^= Availability.GetHashCode(); } if (availableQuantity_ != null) { hash ^= AvailableQuantity.GetHashCode(); } if (Uri.Length != 0) { hash ^= Uri.GetHashCode(); } hash ^= images_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public ProblemResponse UpdateProduct(Product product, IFormFile picture) { string dirPath = "Resources/ProductImgs"; ProblemResponse problemResponse = new ProblemResponse() { Detail = "Wystąpił błąd nieznanego pochodzenia", Status = 500 }; using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); try { Product updatedProduct; if (product.ProductId == Guid.Empty) { Product newProductTmp = new Product(); var newProduct = _mapper.Map(product, newProductTmp); _koopDbContext.Products.Add(newProduct); updatedProduct = newProduct; } else { var productExist = _koopDbContext.Products.SingleOrDefault(p => p.ProductId == product.ProductId); if (productExist is null) { throw new Exception($"Nie znaleziono produktu o podanym Id: {product.ProductId}"); } var productUpdated = _mapper.Map(product, productExist); _koopDbContext.Products.Update(productUpdated); updatedProduct = productUpdated; } _koopDbContext.SaveChanges(); Console.WriteLine($"productID: {updatedProduct.ProductId}"); if (updatedProduct.Category.Any()) { var currentProductCategories = _koopDbContext.ProductCategories.Where(p => p.ProductId == product.ProductId).Include(p => p.Category); var categoriesToAdd = updatedProduct.Category.Where(p => !currentProductCategories.Select(q => q.Category.CategoryName).Contains(p.CategoryName)); var categoriesToRemove = currentProductCategories.Where(p => !updatedProduct.Category.Select(q => q.CategoryName).Contains(p.Category.CategoryName)); foreach (var category in categoriesToAdd) { ProductCategory productCategory = new ProductCategory() { CategoryId = category.CategoryId, ProductId = updatedProduct.ProductId }; _koopDbContext.ProductCategories.Add(productCategory); } _koopDbContext.ProductCategories.RemoveRange(categoriesToRemove); } if (updatedProduct.AvailQuantity.Any()) { var currentAvailableQuantities = _koopDbContext.AvailableQuantities.Where(p => p.ProductId == product.ProductId); var availQuantToAdd = updatedProduct.AvailQuantity.Where(p => !currentAvailableQuantities.Select(q => q.Quantity).Contains(p.Quantity)); var availQuantToRemove = currentAvailableQuantities.Where(p => !updatedProduct.AvailQuantity.Select(q => q.Quantity).Contains(p.Quantity)); foreach (var quantity in availQuantToAdd) { AvailableQuantity availableQuantity = new AvailableQuantity() { // AvailableQuantityId = Guid.Empty, ProductId = updatedProduct.ProductId, Quantity = quantity.Quantity }; _koopDbContext.AvailableQuantities.Add(availableQuantity); } _koopDbContext.AvailableQuantities.RemoveRange(availQuantToRemove); } if (picture is not null && picture.Length > 0) { var fileExtension = picture.FileName.Split('.'); if (fileExtension.Length != 2) { throw new Exception($"Problem z obrazkiem - za dużo kropek"); } var fileName = $"{updatedProduct.ProductId}.{fileExtension[1]}"; var fullPath = Path.Combine(dirPath, fileName); // Remove files with the same name var filesWithSameName = Directory.GetFiles(dirPath, $"{updatedProduct.ProductId}*"); foreach (var file in filesWithSameName) { File.Delete(file); } using (var stream = new FileStream(fullPath, FileMode.Create)) { picture.CopyTo(stream); } updatedProduct.Picture = fullPath; _koopDbContext.Products.Update(updatedProduct); _koopDbContext.SaveChanges(); } else { if (updatedProduct.Picture is null || updatedProduct.Picture.Equals(String.Empty)) { var filesWithSameName = Directory.GetFiles(dirPath, $"{updatedProduct.ProductId}*"); foreach (var file in filesWithSameName) { File.Delete(file); } } } _koopDbContext.SaveChanges(); problemResponse.Detail = "Dane zostały poprawnie zapisane"; problemResponse.Status = 200; scope.Complete(); }
public override string ToString() { return(Name + " " + Quantity.ToString() + " " + AvailableQuantity.ToString() + " " + NoBorrowings.ToString() + "\n"); }