public object Update(String id, ProductReq req) { try { var result = context.Product.FirstOrDefault(value => value.ProductID == id); if (result != null) { result.ProductName = req.ProductName; result.Price = req.Price; result.BrandID = req.BrandID; result.CategoryID = req.CategoryID; result.CreateDate = req.CreateDate; result.Unit = req.Unit; result.UnitsInStock = req.UnitsInStock; result.Discount = req.Discount; result.Description = req.Description; result.Picture = req.Picture; result.Description = req.Note; context.Product.Update(result); context.SaveChanges(); return(result); } else { return("Unable to update: not found ID."); } } catch (Exception ex) { return(ex.StackTrace); } }
public IActionResult CreateProduct([FromBody] ProductReq req) { var res = new SingleRsp(); res = _svc.CreateProduct(req); return(Ok(res)); }
public SingleRsp UpdateProduct(ProductReq pro) { var res = new SingleRsp(); Product products = new Product(); products.Id = pro.Id; products.IdCat = pro.IdCat; products.ProductName = pro.ProductName; products.Title = pro.Title; products.Description = pro.Description; products.Price = pro.Price; products.Quantity = pro.Quantity; products.Size = pro.Size; products.Weight = pro.Weight; products.Color = pro.Color; products.Image = pro.Image; products.Memory = pro.Memory; products.Os = pro.Os; products.CpuSpeed = pro.CpuSpeed; products.CameraPrimary = pro.CameraPrimary; products.Battery = pro.Battery; products.Bluetooth = pro.Bluetooth; products.Wlan = pro.Wlan; products.PromotionPrice = pro.PromotionPrice; res = _rep.UpdateProduct(products); return(res); }
public SingleRsp CreateProduct(ProductReq req) { var res = new SingleRsp(); try { Product c = new Product(); c.ProductId = req.ProductId; c.ProductName = req.ProductName; c.Amount = req.Amount; c.AmountRemaining = req.AmountRemaining; c.OldPrice = req.OldPrice; c.ProductImage = req.ProductImage; c.ManufacturerId = req.ManufacturerId; c.CategoryId = req.CategoryId; c.ProductDescription = req.ProductDescription; // res = base.Create(c); res.Data = c; } catch (Exception ex) { res.SetError(ex.StackTrace); } return(res); }
public IActionResult GetCateProductNameById_Linq([FromBody] ProductReq req) { var res = new SingleRsp(); var cateId = _svc.GetCateProductNameById_Linq(req.CategoryId); res.Data = cateId; return(Ok(res)); }
public IActionResult GetProductNameByProductId_Linq([FromBody] ProductReq req) { var res = new SingleRsp(); var proId = _svc.GetProductNameByProductId_Linq(req.ProductId); res.Data = proId; return(Ok(res)); }
public IActionResult GetProductDetailByProductId_NoPagination([FromBody] ProductReq req) { var res = new SingleRsp(); var proId = _svc.GetProductDetailByProductId_NoPagination(req.ProductId); res.Data = proId; return(Ok(res)); }
public async Task <IActionResult> Put(int id, [FromForm] ProductReq value) { try { if (await _shopContext.Products.AsNoTracking().FirstOrDefaultAsync(a => a.ProductCode == id) != null) { var rename = ""; if (value.File != null) { if (value.File.ContentType.Split("/")[0] == "image") { _environment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); var uploads = Path.Combine(_environment.WebRootPath, "images"); if (!Directory.Exists(uploads)) { Directory.CreateDirectory(uploads); } if (value.File.Length > 0) { rename = Guid.NewGuid() + "." + value.File.ContentType.Split("/")[1]; var fileStream = new FileStream(Path.Combine(uploads, rename), FileMode.Create); await value.File.CopyToAsync(fileStream); } } else { return(Ok(new { status = 0, mgs = "Support image files." })); } } var data = new Products() { ProductCode = id, ProductName = value.ProductName, SellPrice = value.SellPrice, BuyPrice = value.BuyPrice, Img = value.File != null ? rename : _shopContext.Products.AsNoTracking().First(a => a.ProductCode == id).Img, CategoryCode = value.CategoryCode }; _shopContext.Entry(data).State = EntityState.Modified; await _shopContext.SaveChangesAsync(); return(Ok(new { status = 1, mgs = "ok " })); } return(Ok(new { status = 0, mgs = "No data " })); } catch (Exception e) { return(BadRequest(new { status = 0, mgs = e.Message })); } }
public async Task <IActionResult> Post([FromForm] ProductReq value) { try { var rename = ""; if (value.File != null) { if (value.File.ContentType.Split("/")[0] == "image") { _environment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); var uploads = Path.Combine(_environment.WebRootPath, "images"); if (!Directory.Exists(uploads)) { Directory.CreateDirectory(uploads); } if (value.File.Length > 0) { rename = Guid.NewGuid() + "." + value.File.ContentType.Split("/")[1]; var fileStream = new FileStream(Path.Combine(uploads, rename), FileMode.Create); await value.File.CopyToAsync(fileStream); } } else { return(Ok(new { status = 0, mgs = "Support image files." })); } } await _shopContext.Products.AddAsync(new Products() { ProductName = value.ProductName, BuyPrice = value.BuyPrice, SellPrice = value.SellPrice, CategoryCode = value.CategoryCode, Img = rename == "" ? null : rename }); await _shopContext.SaveChangesAsync(); return(Ok(new { status = 1, msg = "ok" })); } catch (Exception e) { return(BadRequest(e.Message)); } }
public SingleRsp UpdateProduct(ProductReq ts) { var res = new SingleRsp(); Product product = new Product(); product.ProductId = ts.ProductId; product.CategoryId = ts.CategoryId; product.ProductName = ts.ProductName; product.UnitPrice = ts.UnitPrice; product.Description = ts.Description; product.Hot = ts.Hot; res = _rep.UpdateProduct(product); res.Data = product; return(res); }
public SingleRsp UpdateProduct(ProductReq pro) { var res = new SingleRsp(); Products products = new Products(); products.ProductId = pro.ProductId; products.ProductName = pro.ProductName; products.CategoryId = pro.CategoryId; products.Price = pro.Price; products.ProductImg = pro.ProductImg; res = _rep.UpdateProduct(products); res.Data = products; return(res); }
public async Task <ServiceResponse <bool> > SaveProduct(List <Product> productsToAdd, int?userId) { var headers = RequestHeaderCreator.GetWebApiClientHeader(); List <ProductReq> prdsReq = new List <ProductReq>(); foreach (var item in productsToAdd) { ProductReq prdReq = new ProductReq(); prdReq.ProductCatId = item.ProductCategoryId; prdReq.ProductDesc = item.Description; prdReq.ProductName = item.ProductCategory; prdReq.ProductQty = item.Quantity; prdReq.ProductRate = item.UnitPrice; prdsReq.Add(prdReq); } AddProductRequest addProdsReq = new AddProductRequest { UserId = userId.Value, Products = prdsReq }; var response = await _restClient .ExecuteAsync <string, AddProductRequest>( HttpVerb.POST, action : "/product/saveProductForSupplier", paramMode : HttpParamMode.BODY, requestBody : addProdsReq, headers : headers, apiRoutePrefix : $"{AppSettings.ApiEndpoint}" ); if (!response.IsOK() || string.IsNullOrEmpty(response.StringData)) { return(new ServiceResponse <bool>(ServiceStatus.Error, data: false, errorCode: LinCTrasactionStatus.Failure.ToString(), errorMessage: "Problem in saving product.")); } var jSonResponse = response.StringData.Replace(@"\", string.Empty); if (jSonResponse.Contains("errorMessage")) { return(new ServiceResponse <bool>(ServiceStatus.Error, data: false, errorCode: LinCTrasactionStatus.Failure.ToString(), errorMessage: "Problem in saving product.")); } return(new ServiceResponse <bool>(ServiceStatus.Success, data: true)); }
public List <ProductReq> returnProductRequestsasList(string requeststring) { List <ProductReq> requestedItemList = new List <ProductReq>(); string[] requestinfo = requeststring.Split(','); for (int i = 0; i < requestinfo.Length; i++) { if (i % 4 == 0) { //first pos is itemcode, second is description, third is qty ProductReq pr = new ProductReq(requestinfo[i], requestinfo[i + 1], requestinfo[i + 2], int.Parse(requestinfo[i + 3])); requestedItemList.Add(pr); } } return(requestedItemList); }
/// <summary> /// 上传单张属性图片,如果需要传多张,可调多次 /// product_id,props 必需 /// </summary> /// <param name="id"></param> /// <param name="product_id"></param> /// <param name="props"></param> /// <param name="image"></param> /// <param name="position"></param> public static ProductRsp ProductPropimgUpload(string session, ProductReq proPropImgload) { try { TopDictionary paramsTable = new TopDictionary(); paramsTable.Add("method", "taobao.product.propimg.upload"); paramsTable.Add("id", proPropImgload.id); paramsTable.Add("image", proPropImgload.Image); paramsTable.Add("product_id", proPropImgload.Id); paramsTable.Add("position", proPropImgload.Position); paramsTable.Add("session", session); return(TopUtils.DeserializeObject <ProductRsp>(TopUtils.InvokeAPI(paramsTable, APIInvokeType.Private))); } catch (System.Exception ex) { throw ex; } }
public object CreateProduct(ProductReq req) { Product product = new Product(); product.ProductID = req.ProductID; product.ProductName = req.ProductName; product.Price = req.Price; product.BrandID = req.BrandID; product.CategoryID = req.CategoryID; product.CreateDate = req.CreateDate; product.Unit = req.Unit; product.UnitsInStock = req.UnitsInStock; product.Discount = req.Discount; product.Description = req.Description; product.Picture = req.Picture; product.Description = req.Note; return(productRep.Create(product)); }
public SingleRsp UpdateProduct(ProductReq pro) { var res = new SingleRsp(); Products prod = new Products(); prod.ProductId = pro.ProductId; prod.Name = pro.Name; prod.Detail = pro.Detail; prod.Price = pro.Price; prod.Image = pro.Image; prod.PriceNew = pro.PriceNew; prod.Date = pro.Date; prod.Status = pro.Status; prod.GroupProductId = pro.GroupProductId; res = _rep.UpdateProduct(prod); return(res); }
//Thêm sản phẩm public SingleRsp CreateProduct(ProductReq productsReq) { var res = new SingleRsp(); Products products = new Products(); products.ProductId = productsReq.ProductId; products.ProductName = productsReq.ProductName; products.CategoryId = productsReq.CategoryId; products.QuantityPerUnit = productsReq.QuantityPerUnit; products.UnitPrice = productsReq.UnitPrice; products.UnitsInStock = productsReq.UnitsInStock; products.UnitsOnOrder = productsReq.UnitsOnOrder; products.ReorderLevel = productsReq.ReorderLevel; products.Discontinued = productsReq.Discontinued; res = _rep.CreateProduct(products); return(res); }
public object Update(String id, ProductReq req) { try { //Khởi tạo đối tượng tìm id trong bảng //Tìm id //Đây là row dữ liệu trả về theo ID var searchResult = _context.Product.FirstOrDefault(value => value.ProductId == id); //Tìm thấy if (searchResult != null) { //Gán giá trị qua search result //Không gán mã searchResult.Name = req.Name; searchResult.Price = req.Price; searchResult.BrandId = req.BrandId; searchResult.CategoryId = req.CategoryId; searchResult.Unit = req.Unit; searchResult.UnitsInStock = req.UnitsInStock; searchResult.Discount = req.Discount; searchResult.UnitsInStock = req.UnitsInStock; searchResult.Description = req.Description; searchResult.CreatedDate = req.CreatedDate; searchResult.Note = req.Note; searchResult.Picture = req.Picture; //Thay đổi theo search result. Không thay đổi theo tham số truyền vào vì sẽ bị duplicate _context.Product.Update(searchResult); _context.SaveChanges(); return(searchResult); } //Không tìm thấy else { return("Unable to update: not found ID."); } } catch (Exception ex) { return(ex.StackTrace); //Xuất ra lỗi } }
public SingleRsp CreateProduct(ProductReq product) { var res = new SingleRsp(); var productNew = new Products() { ProductName = product.ProductName, CategoryId = product.CategoryId, Height = product.Height, Width = product.Width, Length = product.Length, Material = product.Material, Color = product.Color, Price = product.Price, Stock = product.Stock, Image = product.Image, Notes = product.Notes }; res = _rep.CreateProduct(productNew); return(res); }
public object CreateProduct(ProductReq req) { //Khởi tạo giá trị Product product = new Product(); //Gán giá trị product.ProductId = req.ProductId; product.Name = req.Name; product.Price = req.Price; product.BrandId = req.BrandId; product.CategoryId = req.CategoryId; product.Unit = req.Unit; product.UnitsInStock = req.UnitsInStock; product.Discount = req.Discount; product.UnitsInStock = req.UnitsInStock; product.Description = req.Description; product.CreatedDate = req.CreatedDate; product.Note = req.Note; product.Picture = req.Picture; //Tạo giá trị và trả về return(_rep.Create(product)); }
/// <summary> /// 修改一个产品,不包括图片的修改 /// product_id必需 /// </summary> /// <param name="product_id"></param> /// <param name="outer_id"></param> /// <param name="binds"></param> /// <param name="?"></param> /// <param name="name"></param> /// <param name="price"></param> /// <param name="desc"></param> /// <param name="image"></param> public static ProductRsp ProductUpdate(string session, ProductReq Proupdate) { try { TopDictionary paramsTable = new TopDictionary(); paramsTable.Add("method", "taobao.product.update"); paramsTable.Add("product_id", Proupdate.Id); paramsTable.Add("image", Proupdate.Image); paramsTable.Add("outer_id", Proupdate.OuterId); paramsTable.Add("binds", Proupdate.Binds); paramsTable.Add("sale_props", Proupdate.SaleProps); paramsTable.Add("name", Proupdate.Name); paramsTable.Add("price", Proupdate.Price); paramsTable.Add("desc", Proupdate.Description); paramsTable.Add("session", session); return(TopUtils.DeserializeObject <ProductRsp>(TopUtils.InvokeAPI(paramsTable, APIInvokeType.Private))); } catch (System.Exception ex) { throw ex; } }
public IActionResult DeleteProduct([FromBody] ProductReq req) { var res = _svc.DeleteProduct(req.ProductId); return(Ok(res)); }
public static RequestDTB GetRequestDTB(DTBResponseEntity model, string idUnico, string idCliente, string idDomicilio) { List <RelatedProductTestReq> relatedProductTestReqList = new List <RelatedProductTestReq>(); foreach (DTBProducto dTBProducto in model.Productos.ProductRef) { List <DTBProducto> DTBProductoList = new List <DTBProducto>(); List <RealizingResourceTestReq> realizingResourceTestList = new List <RealizingResourceTestReq>(); foreach (DTBEquipoReferencia dTBEquipoReferencia in dTBProducto.Equipos.EquipoRef) { List <CharacteristicReq> characteristicReqList = new List <CharacteristicReq>() { new CharacteristicReq() { name = "MAC", value = dTBEquipoReferencia.MAC }, new CharacteristicReq() { name = "Serial", value = dTBEquipoReferencia.Serial }, new CharacteristicReq() { name = "NroLinea", value = dTBEquipoReferencia.NroLinea }, new CharacteristicReq() { name = "TipoEquipo", value = dTBEquipoReferencia.TipoEquipo }, new CharacteristicReq() { name = "Marca", value = dTBEquipoReferencia.Marca }, new CharacteristicReq() { name = "Modelo", value = dTBEquipoReferencia.Modelo } }; RealizingResourceTestReq realizingResourceTest = new RealizingResourceTestReq() { name = dTBEquipoReferencia.TipoEquipo, characteristic = characteristicReqList }; realizingResourceTestList.Add(realizingResourceTest); } ProductReq productReq = new ProductReq() { id = 1, name = "TELEFONÍA" }; RelatedProductTestReq relatedProductTestReq = new RelatedProductTestReq() { name = dTBProducto.Servicio, product = productReq, realizingResourceTest = realizingResourceTestList }; relatedProductTestReqList.Add(relatedProductTestReq); } RequestDTB requestDTB = new RequestDTB() { name = idUnico, testSpecification = new TestSpecificationReq() { id = "DTB", name = "DIAGNOSTICO TECNICO BASICO", version = "V1" }, customer = new CustomerReq() { id = idCliente }, place = new PlaceReq() { id = idDomicilio }, mode = "ONDEMAND", startDateTime = DateTime.Now.ToString("o"), characteristic = new List <CharacteristicReq>() { new CharacteristicReq() { name = "username", value = "user" }, new CharacteristicReq() { name = "application", value = "app" } }, relatedProductTest = relatedProductTestReqList }; return(requestDTB); }
public IActionResult UpdateProduct(ProductReq req) { var res = _svc.UpdateProduct(req); return(Ok(res)); }
public object UpdateProduct(String id, ProductReq req) { //Tạo giá trị và trả về return(_rep.Update(id, req)); }
public ActionResult Acknowledge(FormCollection formCollection, string command, int reqNumber, string sessionId) { if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true) { if (command == "acknowledge") { //formcollection has all actual quantities associated with requisition, collected by itemnumber-confirmqty. //if all meet, status changed to confirmed, add delivered qty, end. //add confirmqty to requisition, if does not match retrieved qty, have to add back to inventory. //if fall short of requested qty, status close as partial. automatically add new requisition with same infos but only for items fallen short bool complete = true; using (var db = new InventoryDbContext()) { Requisition req = db.requisitions.Where(x => x.reqformNumber == reqNumber).FirstOrDefault(); foreach (ProductReq item in req.productReqs) { int confirmedQty = int.Parse(formCollection[item.productitemnumber + "-confirmqty"]); item.deliveredQuantity = confirmedQty; if (item.retrievedQuantity != item.deliveredQuantity) { //add back to inventory (delivered is always equal or less than retrieved) ProductCatalogue pc = db.productCatalogues.Where(x => x.itemNumber == item.productitemnumber).FirstOrDefault(); pc.quantity = pc.quantity + (item.retrievedQuantity - confirmedQty); //update StockList (voucher) Voucher change = new Voucher(); change.voucherDate = DateTime.Now; change.itemNumber = item.productitemnumber; change.price = 0; change.quantityAdjusted = (item.retrievedQuantity - confirmedQty); change.reason = "Discrepency between retrieved qty and confirmed qty."; change.status = "Automated"; db.vouchers.Add(change); } if (item.deliveredQuantity < item.quantity) { complete = false; } } //if not complete, set current req as partial and create new requisition for remaining items if (complete == false) { req.status = "Partial"; //new requisition is alreay approved, same dates and personnel, awaiting disbursement Requisition newReq = new Requisition(); newReq.approvedBy = req.approvedBy; newReq.comment = "Auto-generated request for undelivered requests."; newReq.dateapproved = req.dateapproved; newReq.datecreated = req.datecreated; newReq.department = req.department; newReq.Employee = req.Employee; newReq.status = "Approved"; //add ProductRequests List <ProductReq> newProductReqs = new List <ProductReq>(); foreach (ProductReq pr in req.productReqs) { if (pr.deliveredQuantity < pr.quantity) { ProductReq newPr = new ProductReq(); newPr.productDesc = pr.productDesc; newPr.productitemnumber = pr.productitemnumber; newPr.quantity = pr.quantity - pr.deliveredQuantity; newPr.req = newReq; newPr.unitOfMeasure = pr.unitOfMeasure; newProductReqs.Add(newPr); } } newReq.productReqs = newProductReqs; db.requisitions.Add(newReq); } else { //if complete, set to complete. Nothing else to do req.status = "Complete"; } db.SaveChanges(); } return(RedirectToAction("Disbursement", new { sessionId })); } else if (command == "cancel") { Requisition r = new Requisition(); using (var db = new InventoryDbContext()) { //Cancel is cancel disbursement, not the request. Set it back to Approved r = db.requisitions.Where(x => x.reqformNumber == reqNumber).FirstOrDefault(); r.status = "Approved"; //add item qty back to inventory, remove retrievedqty from requisition foreach (ProductReq item in r.productReqs) { ProductCatalogue pc = db.productCatalogues.Where(x => x.itemNumber == item.productitemnumber).FirstOrDefault(); //add inventory changes to stockmovt model StockMovement sm = new StockMovement(); sm.movementDate = DateTime.Now; sm.movementDescription = "Disbursement Cancelled"; sm.movementQuantity = item.retrievedQuantity; sm.movementBalance = item.retrievedQuantity + pc.quantity; sm.itemNumber = item.productitemnumber; db.stockmovements.AddOrUpdate(sm); db.SaveChanges(); //update inventory change in pc pc.quantity += item.retrievedQuantity; item.retrievedQuantity = 0; } db.SaveChanges(); } return(RedirectToAction("Disbursement", new { sessionId })); } else { return(null); } } else { return(RedirectToAction("Login", "Login")); } }
public IActionResult UpdateProductPatch(String id, ProductReq req) { var result = _svc.UpdateProduct(id, req); return(Ok(result)); }
public IActionResult CreateProduct(ProductReq req) { var result = _svc.CreateProduct(req); return(Ok(result)); }
public object UpdateProduct(String id, ProductReq req) { return(productRep.Update(id, req)); }