public void CreateProductSize(FormCollection form) { ProductSize productSize = JsonConvert.DeserializeObject <ProductSize>(form["ProductSizeObj"]); decimal length = productSize.ProductSize_Length; decimal width = productSize.ProductSize_Width; decimal height = productSize.ProductSize_Height; if (length > 0 && width > 0 && height > 0) { productSize.ProductSize_Value = length + "x" + width + "x" + height + "" + productSize.ProductSize_Unit; } else if (length > 0 && width > 0) { productSize.ProductSize_Value = length + "x" + width + "" + productSize.ProductSize_Unit; } else if (length > 0) { productSize.ProductSize_Value = length + "" + productSize.ProductSize_Unit; } else { productSize.ProductSize_Value = "Unknown"; } db.ProductSizes.Add(productSize); db.SaveChanges(); }
private void Bind() { IList <string> listSize = new List <string>(); if (!productItemId.Equals(Guid.Empty)) { ProductSize bll = new ProductSize(); var model = bll.GetModel(productItemId); if (model != null) { var li = ddlProductItem_ProductSize.Items.FindByValue(model.ProductItemId.ToString()); if (li != null) { li.Selected = true; } XElement xel = XElement.Parse(model.SizeAppend); var q = from x in xel.Descendants("Data") select new { name = x.Element("Name").Value }; foreach (var item in q) { listSize.Add(item.name); } } } if (listSize.Count == 0) { listSize.Add(""); } rpData.DataSource = listSize; rpData.DataBind(); }
public async Task <IActionResult> Edit(int id, [Bind("id,product,size,quantity")] ProductSize productSize) { if (id != productSize.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productSize); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductSizeExists(productSize.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(productSize)); }
public ActionResult SaveSize(int pid, int sid) { if (db.ProductSizes.Any(A => A.ProductID == pid && A.SizeID == sid)) { return(Json(new { State = false, Message = "新增失敗,此產品已經有此尺寸!!" })); } else { ProductSize _PW = new ProductSize(); _PW.ProductID = pid; _PW.SizeID = sid; db.ProductSizes.Add(_PW); db.SaveChanges(); return(Json(new { State = true, Message = "尺寸新增成功" })); } }
public void UpdateProductSize(FormCollection form) { ProductSize productSize = JsonConvert.DeserializeObject <ProductSize>(form["ProductSizeObj"]); int id = productSize.ProductSize_Id; var productSize_db = db.ProductSizes.Find(id); decimal length = productSize.ProductSize_Length; decimal width = productSize.ProductSize_Width; decimal height = productSize.ProductSize_Height; productSize_db.ProductSize_Length = length; productSize_db.ProductSize_Width = width; productSize_db.ProductSize_Height = height; productSize_db.ProductSize_Unit = productSize.ProductSize_Unit; if (length > 0 && width > 0 && height > 0) { productSize_db.ProductSize_Value = length + "x" + width + "x" + height + "" + productSize.ProductSize_Unit; } else if (length > 0 && width > 0) { productSize_db.ProductSize_Value = length + "x" + width + "" + productSize.ProductSize_Unit; } else if (length > 0) { productSize_db.ProductSize_Value = length + "" + productSize.ProductSize_Unit; } else { productSize_db.ProductSize_Value = "Unknown"; } db.Entry(productSize_db).State = EntityState.Modified; db.SaveChanges(); }
public JsonResult AddSize(ProductSizeViewModel model) { try { if (!ModelState.IsValid) { var result = new { Result = "Erro", Error = true, Id = 0 }; return(Json(result)); } if (!_unitOfWork.Repository <ProductSize>().Any(x => x.Size.ToUpper() == model.Size.ToUpper())) { ProductSize Size = new ProductSize { AddedDate = DateTime.Now, ModifiedDate = DateTime.Now, Size = model.Size, }; _unitOfWork.Repository <ProductSize>().Insert(Size); var result = new { Result = "Tamanho Inserido com sucesso", Error = false, Id = Size.Id }; return(Json(result)); } else { var result = new { Result = "Erro: O Tamanho inserido já existe", Error = true }; return(Json(result)); } } catch (Exception) { throw; } }
public Product(int id, string name, ProductSize size, string price) { this.ID = id; this.Name = name; this.Size = size; this.Price = price; }
public async Task <IActionResult> Create([FromBody] CreateProductSizeRequest productSizeRequest) { var prodSize = new ProductSize { CategoryId = productSizeRequest.CategoryId, Size = productSizeRequest.Size, Unit = productSizeRequest.Unit, }; var status = await _productSizeService.CreateProductSizeAsync(prodSize); if (status == -1) { return(Conflict(new ErrorResponse { message = "Dublicate Entry", status = Conflict().StatusCode })); } if (status == 1) { var response = new ProductSizeResponse { Id = prodSize.Id }; return(Ok(response)); } return(NotFound(new ErrorResponse { message = "Not Found", status = NotFound().StatusCode })); }
public async Task <IActionResult> Update([FromRoute] Int64 id, [FromBody] UpdateProductSizeRequest productSizeRequest) { var prodSize = new ProductSize { Id = id, Size = productSizeRequest.Size, Unit = productSizeRequest.Unit, }; var status = await _productSizeService.UpdateProductSizeAsync(prodSize); if (status == -1) { return(Conflict(new ErrorResponse { message = "Dublicate Entry", status = Conflict().StatusCode })); } if (status == 1) { return(Ok(prodSize)); } return(NotFound(new ErrorResponse { message = "Not Found", status = NotFound().StatusCode })); }
protected override void SetControlsToDto(ProductSize productSize) { productSize.Active = _activeCheckBox.Checked; productSize.Product = _productReferenceEditor.Dto; productSize.Size = _sizeReferenceEditor.Dto; productSize.Price = _priceNumericUpDown.Value; }
public List <ProductSize> GetProductSizeBySubCategoryId(int id) { try { string query = @"SELECT * FROM [dbo].[ProductSize] where SubCatagoryId='" + @id + "'"; SqlCommand cmd = new SqlCommand(query, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); List <ProductSize> aList = new List <ProductSize>(); while (reader.Read()) { ProductSize aCategory = new ProductSize(); aCategory.ProductSizeId = (int)reader["ProductSizeId"]; aCategory.ProductSizeName = reader["ProductSize"].ToString(); aList.Add(aCategory); } reader.Close(); return(aList); } catch (Exception exception) { return(null); } finally { con.Close(); } }
public async Task <List <CartVM> > CheckProductQuantity(List <CartVM> carts) { List <CartVM> cartTemp = new List <CartVM>(); foreach (CartVM item in carts) { ProductSize productSize = await ctx.ProductSize.Where(p => p.ProductId == item.ProductId && p.SizeId == item.SizeId && p.ColorId == item.ColorId) .FirstOrDefaultAsync(); if (productSize.InventoryQuantity < item.Quantity) { cartTemp.Add(new CartVM { ProductId = item.ProductId, ColorId = item.ColorId, SizeId = item.SizeId, Quantity = -1 }); } else { cartTemp.Add(item); } } return(cartTemp); }
public void Create_ProductMetricNonExisting_ThrowsArgumentException() { //Arrange ProductSize invalidProductSize = new ProductSize { ProductMetric = new ProductMetric { Id = 1 }, Size = "L", MetricXValue = 70, MetricYValue = 100, MetricZValue = 75 }; ProductMetric nullProductMetric = null; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); productMetricRepository.Setup(repo => repo.Read(invalidProductSize.ProductMetric.Id)). Returns(nullProductMetric); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act Action actual = () => productSizeService.Create(invalidProductSize); //Assert Assert.Throws <ArgumentException>(actual); }
private void updateSizes(int id, List <SizeModel> model) { List <ProductSize> sizes = setzDB.ProductSizes.Where(x => x.ProductID == id).ToList(); foreach (var size in sizes) { setzDB.ProductSizes.Remove(size); setzDB.SaveChanges(); } if (model != null) { foreach (var item in model) { if (!string.IsNullOrEmpty(item.size)) { ProductSize siz = new ProductSize(); siz.ProductID = id; siz.Size = item.size; setzDB.ProductSizes.Add(siz); setzDB.SaveChanges(); } } } }
public void Read_IdExisting_ReturnsProductSizeWithSpecifiedId() { //Arrange int existingId = 12; ProductSize expected = new ProductSize { Id = existingId, ProductMetric = new ProductMetric { Id = 1 }, Size = "XL", MetricXValue = 70, MetricYValue = -13, MetricZValue = 20 }; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); productSizeRepository.Setup(repo => repo.Read(existingId)). Returns(expected); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act ProductSize actual = productSizeService.Read(existingId); //Assert Assert.Equal(expected, actual); }
private void ValidateNull(ProductSize productSize) { if (productSize == null) { throw new ArgumentNullException("Product Size cannot be null"); } }
private void ValidateSize(ProductSize productSize) { if (string.IsNullOrEmpty(productSize.Size)) { throw new ArgumentException("You need to specify a Size for the ProductSize."); } }
private void ValidateMetricZValue(ProductSize productSize) { if (productSize.MetricZValue <= 0) { throw new ArgumentException("MetricZ cannot be less then or equal to zero"); } }
private void ValidateMetricValues(ProductSize productSize, ProductMetric productMetric) { if (!string.IsNullOrEmpty(productMetric.MetricX)) { ValidateMetricXValue(productSize); } else if (productSize.MetricXValue != default) { throw new ArgumentException("You are not allowed to specify MetricXValue for this ProductSize"); } if (!string.IsNullOrEmpty(productMetric.MetricY)) { ValidateMetricYValue(productSize); } else if (productSize.MetricYValue != default) { throw new ArgumentException("You are not allowed to specify MetricYValue for this ProductSize"); } if (!string.IsNullOrEmpty(productMetric.MetricZ)) { ValidateMetricZValue(productSize); } else if (productSize.MetricZValue != default) { throw new ArgumentException("You are not allowed to specify MetricZValue for this ProductSize"); } }
public List <Product> GetProductWithDetails(int id) { try { Product mainProduct = _shoppingCartDbContext.Products.FirstOrDefault(p => p.Id == id); List <ProductDetails> subProduct = _shoppingCartDbContext.ProductDetails.Where(p => p.ProductId == id && p.Stock > 0).ToList(); List <Product> returnProducts = new List <Product>(); foreach (ProductDetails p in subProduct) { Product addProduct = new Product(); addProduct.BaseProduct = mainProduct.Id; addProduct.Id = p.Id; addProduct.Name = mainProduct.Name; addProduct.CategoryId = mainProduct.CategoryId; addProduct.Description = mainProduct.Description; addProduct.Discount = mainProduct.Discount; addProduct.Price = mainProduct.Price; addProduct.DefaultImage = p.Image; addProduct.Size = ProductSize.GetName(typeof(ProductSize), p.Size); addProduct.Stock = p.Stock; returnProducts.Add(addProduct); } return(returnProducts); } catch { throw; } }
public void Update_ProductMetricSpecified_ThrowsArgumentException() { //Arrange ProductSize invalidProductSize = new ProductSize { Id = 1, ProductMetric = new ProductMetric { Id = 1 }, Size = "L", MetricXValue = 70, MetricYValue = 100, MetricZValue = 75 }; Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object, productMetricRepository.Object); //Act Action actual = () => productSizeService.Update(invalidProductSize); //Assert Assert.Throws <ArgumentException>(actual); }
public async Task <IActionResult> PutProductSize(int id, ProductSize productSize) { if (id != productSize.ProductId) { return(BadRequest()); } _context.Entry(productSize).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductSizeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public List <Product> GetSimilarProducts(int id) { try { var result = _shoppingCartDbContext.Products.Where(p => p.CategoryId == id).Take(5).ToList(); List <Product> returnProducts = new List <Product>(); foreach (Product p in result) { Product addProduct = new Product(); addProduct = p; var result_ = _shoppingCartDbContext.ProductDetails.FirstOrDefault(pr => pr.ProductId == addProduct.Id && pr.Stock > 0); if (result_ != null) { addProduct.BaseProduct = p.Id; addProduct.Id = result_.Id; addProduct.DefaultImage = result_.Image; addProduct.Size = ProductSize.GetName(typeof(ProductSize), result_.Size); addProduct.Stock = result_.Stock; returnProducts.Add(addProduct); } } return(returnProducts); } catch { throw; } }
protected override void SetDtoToControls(ProductSize productSize) { _activeCheckBox.Checked = productSize.Active; _productReferenceEditor.Dto = productSize.Product; _sizeReferenceEditor.Dto = productSize.Size; _priceNumericUpDown.Value = productSize.Price; }
public bool AddUpdateDeleteProductSize(ProductSize ProductSize, string action) { bool isSuccess = true; try { //brand.App_User = ReadConfigData.GetDBLoginUser(); //brand.Audit_User = GlobalUser.getGlobalUser().UserName; //brand.RegionID = Convert.ToInt32(GlobalUser.getGlobalUser().RegionID); //brand.DisplayOrder = 1; //brand.VersionDataID = vid; //brand.VersionAction = action; if (action == "I") { Insert(ProductSize); } else if (action == "U") { Update(ProductSize); } else if (action == "D") { Delete(ProductSize); } _unitOfWork.SaveChanges(); } catch (Exception ex) { isSuccess = false; throw ex; } return(isSuccess); }
public IHttpActionResult PutProductSize(int id, ProductSize productSize) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productSize.Id) { return(BadRequest()); } db.Entry(productSize).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductSizeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public Product(string code, string name, Color color, float price, ProductSize productSize) { this.code = code; this.name = name; this.color = color; this.price = price; this.productSize = productSize; }
public Product(string id, string name, Color color, float price, ProductSize size) { this.Id = id; this.Name = name; this.Color = color; this.Price = price; this.Size = size; }
public int ChangeSizePrice(ProductSize P) { dbCon.openCon(); cmd = new SqlCommand("update ProductSize set sizePrice = '" + P.sizePrice + "',CurrentStatus = '" + P.CurrentStatus + "' where ItemType = '" + P.ItemType + "' and ProductSize = '" + P.ProSize + "'", dbCon.con); int status = cmd.ExecuteNonQuery(); dbCon.closeCon(); return status; }
public ActionResult DeleteConfirmed(int id) { ProductSize productSize = db.ProductSize.Find(id); db.ProductSize.Remove(productSize); db.SaveChanges(); return(RedirectToAction("Index")); }
public IEnumerable<Product> BySize(IList<Product> products, ProductSize productSize) { foreach (var product in products) { if ((product.Size == productSize)) yield return product; } }
public int createSize(ProductSize P) { dbCon.openCon(); cmd = new SqlCommand("insert into ProductSize (PSizeId,ItemType,ProductSize,CurrentStatus) values('" + P.PSizeId + "','" + P.ItemType + "','" + P.ProSize + "','" + P.CurrentStatus + "')", dbCon.con); int status = cmd.ExecuteNonQuery(); dbCon.closeCon(); return status; }
public IEnumerable<Product> ByColorAndSize(IList<Product> products, ProductColor productColor, ProductSize productSize) { foreach (var product in products) { if ((product.Color == productColor) && (product.Size == productSize)) yield return product; } }
public Product(ProductColor color, ProductSize size) { this.Color = color; this.Size = size; }
public SizeSpec(ProductSize productSize) { ProductSize = productSize; }
public SizeSpecification(ProductSize productSize) { _productSize = productSize; }
public static ProductSize CreateProductSize(long productSizeID, string size) { ProductSize productSize = new ProductSize(); productSize.ProductSizeID = productSizeID; productSize.Size = size; return productSize; }
public void AddToProductSizes(ProductSize productSize) { base.AddObject("ProductSizes", productSize); }
public ColorAndSizeSpecification(ProductColor productColor, ProductSize productSize) { this.productColor = productColor; this.productSize = productSize; }