Skip to content

Commit

Permalink
Fixed stocklevel limit error
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinahmadov committed Jul 14, 2021
1 parent 6916cc0 commit f4ad343
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
7 changes: 3 additions & 4 deletions Catalog.Client/CustomControls/TopControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public TopControl()
this.Visible = false;
InitializeComponent();
this.radLayoutControl.Visible = false;
this.radSettingsDialog = null;

this.radSettingsDialog = new SettingsTabbedForm();
this.radSettingsButton.Click += RadSettingsButton_Click;

this.radSearchTextBox.Size = new Size(200, 100);
this.radSearchTextBox.Location = new Point(10, 200);
this.radSearchTextBox.NullText = "Найти";

this.Margin = new Padding(0);
//this.Load += TopControl_Load;
this.VisibleChanged += TopControl_VisibleChanged;
}

Expand All @@ -45,12 +45,11 @@ private void TopControl_VisibleChanged(Object sender, EventArgs e)

private void TopControl_Load(Object sender, EventArgs e)
{
radSettingsDialog.Hide();
this.radSettingsDialog.Hide();
}

private void RadSettingsButton_Click(Object sender, EventArgs e)
{
this.radSettingsDialog = new SettingsTabbedForm();
this.radSettingsDialog.Show();
}

Expand Down
4 changes: 2 additions & 2 deletions Catalog.Client/CustomForms/SettingsTabbedForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ private void SubmitButton_Click(Object sender, EventArgs e)
Settings.Default.LoadImage = this.radLoadImageCheckBox.Checked;
Settings.Default.UpdateInterval = Convert.ToInt32(this.updateItervalSpinControl.Value);
Settings.Default.Commit();
Close();
Hide();
}

private void CancelButton_Click(Object sender, EventArgs e)
{
Close();
Hide();
}

private void LoginButton_Click(Object sender, EventArgs e)
Expand Down
14 changes: 14 additions & 0 deletions Catalog.Common/Repository/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ public static void SaveChanges(Action callback = null)
$"StackTrace:\n{dbe.StackTrace}\n" +
$"Detailed message:\n{dbe.InnerException?.Message}");
}
catch (DbEntityValidationException ev)
{
foreach (var eve in ev.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
catch (Exception ex)
{
Debug.WriteLine($"2. Error occurred while saving changes: {ex.Message}\n" +
Expand Down
14 changes: 4 additions & 10 deletions Catalog.Common/Repository/WebWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ public static int InitProducts()
var productInventories = new List<ProductInventory>();
var cartItems = new List<ShoppingCartItem>();

MainRepository.ResetCaches(CacheType.PRODUCT, CacheType.INVENTORY, CacheType.CART_ITEM);

var responses = RestAPIManager.FetchProducts().Result;
int index = MainRepository.ProductsCache.Count;
int createCount = 0;
Expand All @@ -161,10 +159,6 @@ public static int InitProducts()
{
var json = new ProductJSON(data);
var productId = json.Id;

if (productId >= 200)
break;

var product = json.AsEntity();
var stockLevel = new StockLevel(json.Stock1, json.Stock2);
var sub1 = json.Sub1;
Expand Down Expand Up @@ -238,6 +232,10 @@ public static int InitProducts()
}
}

Console.WriteLine($"Products {products.Count}");
Console.WriteLine($"ProductInventories {productInventories.Count}");
Console.WriteLine($"CartItems {cartItems.Count}");

Repository.Context.Products.AddRange(products);
Repository.Context.ProductInventories.AddRange(productInventories);
Repository.Context.ShoppingCartItems.AddRange(cartItems);
Expand Down Expand Up @@ -292,10 +290,6 @@ public static void InitProductPhotos()
var json = new ProductJSON(data);
var photoId = product.ID;
var fileName = json.Image;

if (json.Id >= 200)
break;

var photo = new ProductPhoto(photoId, fileName) { Product = product };
productPhotos.Add(photo);

Expand Down
9 changes: 5 additions & 4 deletions Catalog.Common/Service/ShopModel.Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

namespace Catalog.Common.Service
{
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

public partial class ShopEntities : DbContext
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

public partial class ShopEntities : DbContext
{
public ShopEntities()
: base("name=ShopEntities")
Expand Down
8 changes: 4 additions & 4 deletions Catalog.Common/Service/ShopModel.edmx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@
<Property Name="ProductID" Type="int" Nullable="false" />
<Property Name="ProductCategoryID" Type="int" Nullable="false" />
<Property Name="ProductSubcategoryID" Type="int" Nullable="true" />
<Property Name="StockLevel1" Type="nvarchar" Nullable="false" DefaultValue="&quot;-&quot;" MaxLength="5" />
<Property Name="StockLevel2" Type="nvarchar" Nullable="false" DefaultValue="&quot;-&quot;" MaxLength="5" />
<Property Name="StockLevel1" Type="nvarchar(max)" Nullable="false" DefaultValue="&quot;-&quot;" />
<Property Name="StockLevel2" Type="nvarchar(max)" Nullable="false" DefaultValue="&quot;-&quot;" />
<Property Name="Pack" Type="nvarchar(max)" Nullable="false" DefaultValue="&quot;&quot;" />
<Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
<Property Name="ModifiedDate" Type="datetime" Nullable="false" />
Expand Down Expand Up @@ -595,8 +595,8 @@
<Property Name="ProductID" Type="Int32" Nullable="false" />
<Property Name="ProductCategoryID" Type="Int32" Nullable="false" />
<Property Name="ProductSubcategoryID" Type="Int32" Nullable="true" />
<Property Name="StockLevel1" Type="String" Nullable="false" DefaultValue="&quot;-&quot;" MaxLength="5" />
<Property Name="StockLevel2" Type="String" Nullable="false" MaxLength="5" DefaultValue="&quot;-&quot;" />
<Property Name="StockLevel1" Type="String" Nullable="false" DefaultValue="&quot;-&quot;" />
<Property Name="StockLevel2" Type="String" Nullable="false" DefaultValue="&quot;-&quot;" />
<Property Name="Pack" Type="String" Nullable="false" DefaultValue="&quot;&quot;" Unicode="true" />
<Property Name="rowguid" Type="Guid" Nullable="false" />
<Property Name="ModifiedDate" Type="DateTime" Nullable="false" Precision="3" />
Expand Down
6 changes: 3 additions & 3 deletions Catalog.Common/Service/ShopModel.edmx.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 07/13/2021 17:54:38
-- Date Created: 07/14/2021 08:12:13
-- Generated from EDMX file: C:\Users\Alvin\source\repos\Catalog\Catalog.Common\Service\ShopModel.edmx
-- --------------------------------------------------

Expand Down Expand Up @@ -215,8 +215,8 @@ CREATE TABLE [dbo].[ProductInventories] (
[ProductID] int NOT NULL,
[ProductCategoryID] int NOT NULL,
[ProductSubcategoryID] int NULL,
[StockLevel1] nvarchar(5) NOT NULL,
[StockLevel2] nvarchar(5) NOT NULL,
[StockLevel1] nvarchar(max) NOT NULL,
[StockLevel2] nvarchar(max) NOT NULL,
[Pack] nvarchar(max) NOT NULL,
[rowguid] uniqueidentifier NOT NULL,
[ModifiedDate] datetime NOT NULL
Expand Down

0 comments on commit f4ad343

Please sign in to comment.