コード例 #1
0
        public IActionResult Post([FromBody] Product value)
        {
            value.Id = 5;
            var result = new ResultProduct {
                Error = null, Results = new List <Product> {
                    value
                }
            };

            return(Ok(result));
        }
コード例 #2
0
        public ResultProduct UpdateProduct()
        {
            //stt: nhập kho: NK
            // Xuất kho : XK
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/product/updateproduct",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

            var result = new ResultProduct()
            {
                id  = "1",
                msg = "success"
            };

            var requestContent = Request.Content.ReadAsStringAsync().Result;

            log.Content = requestContent;
            try
            {
                var jsonserializer = new JavaScriptSerializer();
                var paser          = jsonserializer.Deserialize <RequestProduct>(requestContent);
                //  log.Content = new JavaScriptSerializer().Serialize(paser);

                if (!mongoHelper.checkLoginSession(paser.user, paser.token))
                {
                    throw new Exception("Tài khoản của bạn đã bị đăng nhập trên một thiết bị khác!");
                }

                WavehouseInfo wareActionInfo = new WavehouseInfo();

                var staff = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault();

                if (staff != null)
                {
                    wareActionInfo.wCode = staff.HaiBranch.Code;
                    wareActionInfo.wName = staff.HaiBranch.Name;

                    var userStaff = db.AspNetUsers.Where(p => p.UserName == paser.user).FirstOrDefault();

                    var role = userStaff.AspNetRoles.FirstOrDefault();

                    if (role.Name == "Warehouse")
                    {
                        wareActionInfo.wType = "W";
                    }
                    else
                    {
                        wareActionInfo.wType = "B";
                    }
                }
                else
                {
                    var agency = db.CInfoCommons.Where(p => p.UserLogin == paser.user).FirstOrDefault();

                    if (agency != null)
                    {
                        wareActionInfo.wCode = agency.CCode;
                        wareActionInfo.wName = agency.CName;
                        wareActionInfo.wType = agency.CType;
                    }
                }

                // check user receiver
                WavehouseInfo wareReceiInfo = null;
                // lay thong tin noi nhan
                if (!String.IsNullOrEmpty(paser.receiver.Trim()) && paser.status == "XK")
                {
                    wareReceiInfo = new WavehouseInfo();
                    var branchReceiver = db.HaiBranches.Where(p => p.Code == paser.receiver).FirstOrDefault();
                    if (branchReceiver != null)
                    {
                        wareReceiInfo.wType = "B";
                        wareReceiInfo.wCode = branchReceiver.Code;
                        wareReceiInfo.wName = branchReceiver.Name;
                    }
                    else
                    {
                        var agencyReceiver = db.CInfoCommons.Where(p => p.CCode == paser.receiver).FirstOrDefault();
                        if (agencyReceiver != null)
                        {
                            wareReceiInfo.wType = agencyReceiver.CType;
                            wareReceiInfo.wCode = agencyReceiver.CCode;
                            wareReceiInfo.wName = agencyReceiver.CName;
                        }
                    }

                    if (String.IsNullOrEmpty(wareReceiInfo.wCode) || wareActionInfo.wCode == wareReceiInfo.wCode)
                    {
                        throw new Exception("Sai thông tin nơi nhập hàng");
                    }
                }

                ProductScanAction wareAction = null;

                if (paser.status == "NK")
                {
                    wareAction = new ImportAction(db, wareActionInfo, paser.user, null);
                }
                else if (paser.status == "XK")
                {
                    wareAction = new ExportAction(db, wareActionInfo, paser.user, wareReceiInfo);
                }

                if (wareAction == null)
                {
                    throw new Exception("Sai thông tin quét");
                }

                string msg = wareAction.checkRole();
                if (msg != null)
                {
                    throw new Exception(msg);
                }

                // kiem tra nhap kho
                List <GeneralInfo> productsReturn = new List <GeneralInfo>();
                foreach (string barcode in paser.products)
                {
                    BarcodeHistory resultSave = wareAction.Handle(barcode);
                    db.BarcodeHistories.Add(resultSave);
                    db.SaveChanges();
                    productsReturn.Add(new GeneralInfo()
                    {
                        code    = resultSave.Barcode,
                        name    = resultSave.ProductName,
                        status  = resultSave.Messenge,
                        success = Convert.ToInt32(resultSave.IsSuccess)
                    });
                }

                result.products = productsReturn;
            }
            catch (Exception e)
            {
                result.id  = "0";
                result.msg = e.Message;
                log.Sucess = 0;
            }

            log.ReturnInfo = new JavaScriptSerializer().Serialize(result);
            mongoHelper.createHistoryAPI(log);

            return(result);
        }
コード例 #3
0
        public ResultProduct HelpAgencyImport()
        {
            //stt: nhập kho: NK
            // Xuất kho : XK
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/product/helpagencyimport",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

            var result = new ResultProduct()
            {
                id  = "1",
                msg = "success"
            };

            var requestContent = Request.Content.ReadAsStringAsync().Result;

            log.Content = requestContent;
            try
            {
                var jsonserializer = new JavaScriptSerializer();
                var paser          = jsonserializer.Deserialize <RequestProductHelp>(requestContent);
                log.Content = new JavaScriptSerializer().Serialize(paser);


                if (!mongoHelper.checkLoginSession(paser.user, paser.token))
                {
                    throw new Exception("Tài khoản của bạn đã bị đăng nhập trên một thiết bị khác!");
                }

                WavehouseInfo wareActionInfo = new WavehouseInfo();
                var           staff          = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault();
                if (staff == null)
                {
                    throw new Exception("Chỉ nhân viên công ty mới sử dụng chức năng này");
                }

                var agency = db.CInfoCommons.Where(p => p.CCode == paser.agency).FirstOrDefault();

                if (agency != null)
                {
                    wareActionInfo.wCode = agency.CCode;
                    wareActionInfo.wName = agency.CName;
                    wareActionInfo.wType = agency.CType;
                }
                else
                {
                    throw new Exception("Sai mã khách hàng");
                }

                // kiem tra toa do

                ProductScanAction wareAction = new ImportAction(db, wareActionInfo, paser.user, null);

                string msg = wareAction.checkRole();
                if (msg != null)
                {
                    throw new Exception(msg);
                }

                // kiem tra nhap kho
                List <GeneralInfo> productsReturn = new List <GeneralInfo>();
                foreach (string barcode in paser.products)
                {
                    BarcodeHistory resultSave = wareAction.Handle(barcode);
                    resultSave.StaffHelp = staff.Code;
                    if (paser.nearAgency == 1)
                    {
                        resultSave.StaffHelpIssue = "locationin";
                    }
                    else
                    {
                        resultSave.StaffHelpIssue = "locationout";
                    }
                    resultSave.LocationStaff = paser.latitude + "|" + paser.longitude;
                    db.BarcodeHistories.Add(resultSave);
                    db.SaveChanges();

                    productsReturn.Add(new GeneralInfo()
                    {
                        code    = resultSave.Barcode,
                        name    = resultSave.ProductName,
                        status  = resultSave.Messenge,
                        success = Convert.ToInt32(resultSave.IsSuccess)
                    });
                }

                result.products = productsReturn;
            }
            catch (Exception e)
            {
                result.id  = "0";
                result.msg = e.Message;
                log.Sucess = 0;
            }

            log.ReturnInfo = new JavaScriptSerializer().Serialize(result);
            mongoHelper.createHistoryAPI(log);

            return(result);
        }