Beispiel #1
0
        public JsonResult Update([FromBody] MaterialProduct obj)
        {
            var msg = new JMessage {
                Title = "", Error = false
            };

            try
            {
                var item = _context.MaterialProducts.FirstOrDefault(x => x.ProductCode == obj.ProductCode);
                item.ProductName = obj.ProductName;
                item.Note        = obj.Note;
                item.Barcode     = obj.Barcode;
                item.GroupCode   = obj.GroupCode;
                item.TypeCode    = obj.TypeCode;
                item.Status      = obj.Status;
                item.UpdatedBy   = ESEIM.AppContext.UserName;
                item.UpdatedTime = DateTime.Now;
                _context.MaterialProducts.Update(item);
                _context.SaveChanges();
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("MLP_MSG_SUPPLIES"));
            }
            catch
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_FAILED"), CommonUtil.ResourceValue("MLP_MSG_SUPPLIES"));
            }
            return(Json(msg));
        }
Beispiel #2
0
        public JsonResult Insert([FromBody] MaterialProduct obj)
        {
            var msg = new JMessage {
                Title = "", Error = false
            };

            try
            {
                var model = _context.MaterialProducts.Where(x => x.ProductCode.Equals(obj.ProductCode)).FirstOrDefault();
                if (model == null)
                {
                    obj.CreatedBy   = ESEIM.AppContext.UserName;
                    obj.CreatedTime = DateTime.Now;
                    _context.MaterialProducts.Add(obj);
                    _context.SaveChanges();
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("MLP_MSG_SUPPLIES"));
                }
                else
                {
                    msg.Error = true;
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_EXITS"), CommonUtil.ResourceValue("MLP_CURD_LBL_SUPPLIES_CODE"));
                }
            }
            catch
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_FAILED"), CommonUtil.ResourceValue("MLP_MSG_SUPPLIES"));
            }
            return(Json(msg));
        }
Beispiel #3
0
        public int saveEditedProduct(int iProjectId)
        {
            Product editedProduct = _productsConnectDB.selectProduct(productId);            // get current product from database

            editedProduct.code      = sCode.sInput;
            editedProduct.name      = sProductName.sInput;
            editedProduct.active    = active;
            editedProduct.coverId   = clCover.iSelectedValue;
            editedProduct.typeId    = clType.iSelectedValue;
            editedProduct.projectId = iProjectId;
            editedProduct.profileId = clProfile.iSelectedValue;
            editedProduct.imagePath = imagePath;

            int iEditedProductId = _productsConnectDB.editInsertAndSubmit(editedProduct);   // insert edited product to database

            _materialProductConnectDB.deleteWhereProductId(productId);

            if (iEditedProductId != -1)
            {
                MaterialProduct newMaterialProduct;
                // for every IO position
                foreach (var ioPosition in _obcIOPositions.ToList())
                {
                    // for every material in every IO position
                    foreach (var material in ioPosition.obcAddedMaterials.ToList())
                    {
                        newMaterialProduct                    = new MaterialProduct();
                        newMaterialProduct.productId          = iEditedProductId;
                        newMaterialProduct.materialIOPosition = ioPosition.iIOPositionSelectedValuePath + 1;
                        newMaterialProduct.materialId         = material.iSelectedvaluePath;

                        _materialProductConnectDB.insert(newMaterialProduct);
                    }
                }
                _materialProductConnectDB.submit();
            }
            return(iEditedProductId);
        }
Beispiel #4
0
        public int saveNewProduct(int iProjectId)
        {
            Product saveNewProduct = new Product();

            saveNewProduct.code      = sCode.sInput;
            saveNewProduct.name      = sProductName.sInput;
            saveNewProduct.active    = active;
            saveNewProduct.coverId   = clCover.iSelectedValue;
            saveNewProduct.typeId    = clType.iSelectedValue;
            saveNewProduct.projectId = iProjectId;
            saveNewProduct.profileId = clProfile.iSelectedValue;
            saveNewProduct.imagePath = imagePath;

            int iNewProductId = _productsConnectDB.insertAndSubmit(saveNewProduct);

            if (iNewProductId != -1)
            {
                MaterialProduct newMaterialProduct;
                // for every IO position
                foreach (var ioPosition in _obcIOPositions.ToList())
                {
                    // for every material in every IO position
                    foreach (var material in ioPosition.obcAddedMaterials.ToList())
                    {
                        newMaterialProduct                    = new MaterialProduct();
                        newMaterialProduct.productId          = iNewProductId;
                        newMaterialProduct.materialIOPosition = ioPosition.iIOPositionSelectedValuePath + 1;
                        newMaterialProduct.materialId         = material.iSelectedvaluePath;

                        _materialProductConnectDB.insert(newMaterialProduct);
                    }
                }
                _materialProductConnectDB.submit();
            }

            return(iNewProductId);
        }