internal void Delete(ProductIn productIn) { command = database.GetStoredProcCommand("spProductInDelete"); database.AddInParameter(command, "@ProductInID", SqlDbType.Int, productIn.ProductInID.Value); database.ExecuteNonQuery(command); }
public ProductDTO(ProductIn productIn) { Name = productIn.Name; Description = productIn.Description; RetailPrice = productIn.RetailPrice; WholeSalePrice = productIn.WholeSalePrice; CategoryID = productIn.CategoryID; }
public ActionResult DeleteConfirmed(int id) { ProductIn productIn = db.ProducsIn.Find(id); db.ProducsIn.Remove(productIn); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ProductInID,ProductCode,Qty,Price,Notes")] ProductIn productIn) { if (ModelState.IsValid) { db.Entry(productIn).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductID = new SelectList(db.Products, "ProductCode", "ProductCode", productIn.ProductCode); return(View(productIn)); }
// GET: ProductIns/Details/5 //[Authorize(Roles = "admin")] public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductIn productIn = db.ProducsIn.Find(id); if (productIn == null) { return(HttpNotFound()); } return(View(productIn)); }
public IActionResult Update([FromBody] ProductIn productIn, string id) { try { var productOut = productService.Update(id, productIn); return(Json(productOut)); } catch (ArgumentException ex) { Response.StatusCode = 403; var msg = new JsonMessage("Исключение на свойстве: " + ex.Message, ""); return(Json(msg)); } }
// GET: ProductIns/Edit/5 //[Authorize(Roles = "admin")] public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductIn productIn = db.ProducsIn.Find(id); if (productIn == null) { return(HttpNotFound()); } ViewBag.ProductID = new SelectList(db.Products, "ProductCode", "ProductCode", productIn.ProductCode); return(View(productIn)); }
public ActionResult Create([Bind(Include = "ProductInID,ProductCode,Date,Qty,Notes")] ProductIn productIn) { productIn.Date = System.DateTime.Today; var price = db.Products.Where(o => o.ProductCode == productIn.ProductCode).Select(o => o.Price).FirstOrDefault(); productIn.Price = productIn.Qty * price; if (ModelState.IsValid) { db.ProducsIn.Add(productIn); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductID = new SelectList(db.Products, "ProductCode", "ProductCode", productIn.ProductCode); return(View(productIn)); }
public async Task <ActionResult <ProductOut> > PostProduct([FromForm] ProductIn productIN) { try { if (productIN.ID == 0) { return(await m_Handler.AddNewProduct(productIN)); } return(await m_Handler.UpdateProduct(productIN)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } }
public ActionResult DeleteConfirmed(int id) { ProductIn productIn = db.ProducsIn.Find(id); var productName = db.Products.Where(o => o.ProductCode == productIn.ProductCode).FirstOrDefault().ProductName; db.ProducsIn.Remove(productIn); db.SaveChanges(); Logger.AddLog( User.Identity.Name, productIn.ProductInID, Logger.ProductIn, Logger.Delete, Logger.DescriptionQtyPrice(productIn.ProductCode, productName, productIn.Qty, productIn.Qty, productIn.Price, productIn.Price) ); return(RedirectToAction("Index")); }
public async Task <ActionResult <ProductOut> > UpdateProduct(ProductIn productIN) { try { var productDTO = m_Context.GetProduct(productIN.ID); productDTO.CopyFrom(productIN); UpdateImage(productDTO, productIN); //await m_HttpController.PutProduct(productDTO.ID, productDTO); await UpdateProduct(productDTO.ID, productDTO); return(new ProductOut(m_Context, productDTO)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } }
public ProductOut Create(ProductIn productIn) { var product = MapHelper.Map <ProductIn, Product>(productIn); var pType = ffContext.ProductTypes .FirstOrDefault(p => p.Enabled && p.Id == productIn.ProductTypeId); product.ProductType = pType ?? throw new ArgumentException("productTypeId"); ffContext.Products.Add(product); ffContext.SaveChanges(); if (product.Image != null) { FileHelper.SaveFormFile(productIn.Image, environment.WebRootPath + "\\Images", product.Id + ".png"); product.Image = product.Id + ".png"; ffContext.SaveChanges(); } return(Get(product.Id)); }
internal int Save(ProductIn productIn) { command = database.GetStoredProcCommand("spProductInSave"); if (productIn.ProductInID.HasValue) { database.AddInParameter(command, "@ProductInID", SqlDbType.Int, productIn.ProductInID.Value); } database.AddInParameter(command, "@CategoryID", SqlDbType.Int, productIn.CategoryID); database.AddInParameter(command, "@Name", SqlDbType.NVarChar, productIn.Name); database.AddInParameter(command, "@UnitID", SqlDbType.Int, productIn.UnitID); database.AddInParameter(command, "@Amount", SqlDbType.Float, productIn.Amount); database.AddInParameter(command, "@OutAmount", SqlDbType.Float, productIn.OutAmount); database.AddInParameter(command, "@Count", SqlDbType.Int, productIn.Count); database.AddInParameter(command, "@CurrCount", SqlDbType.Int, productIn.CurrCount); database.AddInParameter(command, "@MinCount", SqlDbType.Int, productIn.MinCount); database.AddInParameter(command, "@ProducKey", SqlDbType.Int, productIn.ProducKey); database.AddInParameter(command, "@CountryID", SqlDbType.Int, productIn.CountryID); database.AddInParameter(command, "@PlaceName", SqlDbType.NVarChar, productIn.PlaceName); database.AddInParameter(command, "@PlaceID", SqlDbType.Int, productIn.PlaceID); return((int)database.ExecuteScalar(command)); }
/* return the path to save in the DB */ private string UpdateImage(ProductDTO productDTO, ProductIn productIN) { string pathToSave = string.Empty; if (productIN.Images == null || productIN.Images.Count <= 0) { pathToSave = m_Context.GetProduct(productDTO.ID).ImagePath; return(pathToSave); } var image = productIN.Images[0]; if (image.Length > 0) { string FolderPath = Path.Combine(m_HttpController.GetHostingEnvironment().WebRootPath, SharedMediaConfigOptions.Products, productDTO.ID.ToString()); if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } // copy the image var finalPath = Path.Combine(FolderPath, image.FileName); using (var fs = new FileStream(finalPath, FileMode.Create)) image.CopyTo(fs); var relativeDestPath = Path.Combine(SharedMediaConfigOptions.Products, productDTO.ID.ToString(), image.FileName); pathToSave += relativeDestPath + ","; } // remove last ',' if (pathToSave != null && pathToSave.Length > 0) { pathToSave = pathToSave.Substring(0, pathToSave.Length - 1); } productDTO.ImagePath = pathToSave; return(pathToSave); }
public ActionResult Edit([Bind(Include = "ProductInID,ProductCode,Qty,Notes")] ProductIn productIn) { if (ModelState.IsValid) { ProductIn obj = db.ProducsIn.Find(productIn.ProductInID); int qtyBefore = obj.Qty; int priceBefore = obj.Price; obj.Qty = productIn.Qty; var price = db.Products.Where(o => o.ProductCode == productIn.ProductCode).Select(o => o.Price).FirstOrDefault(); obj.Price = productIn.Qty * price; obj.ProductCode = productIn.ProductCode; obj.Notes = productIn.Notes; var oldobj = db.ProducsIn.Find(productIn.ProductInID); var productName = db.Products.Where(o => o.ProductCode == productIn.ProductCode).FirstOrDefault().ProductName; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); Logger.AddLog( User.Identity.Name, productIn.ProductInID, Logger.ProductIn, Logger.Edit, Logger.DescriptionQtyPrice(productIn.ProductCode, productName, productIn.Qty, qtyBefore, productIn.Price, priceBefore) ); return(RedirectToAction("Index")); } ViewBag.ProductID = new SelectList(db.Products, "ProductCode", "ProductCode", productIn.ProductCode); return(View(productIn)); }
public ProductDTO(ProductIn productIn) : base(productIn) { CategoryID = productIn.CategoryID; }