public async Task <ServiceResponseBase> Update(ProductViewModel vm, AccountViewModel account)
        {
            try
            {
                var isExist = await _context.Product.AnyAsync(o => o.BarCode == vm.BarCode &&
                                                              o.CompanyId == account.CompanyId && o.Id != vm.Id);

                if (isExist)
                {
                    return(new ServiceResponseBase()
                    {
                        Status = Status.error, Message = "存在重复条码"
                    });
                }
                var product = await _context.Product.FirstOrDefaultAsync(o => o.Id == vm.Id);

                vm.SnNum = "";
                Mapper.Map(vm, product);
                _context.Entry(product).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
Esempio n. 2
0
        public async Task <ServiceResponseBase> Update(BadReportViewModel vm, List <BadReportDetailViewModel> details, AccountViewModel account)
        {
            try
            {
                var badReport = await _context.BadReport.FirstOrDefaultAsync(o => o.Id == vm.Id);

                badReport.BadType               = vm.BadType;
                badReport.Remark                = vm.Remark;
                badReport.CompanyId             = account.CompanyId;
                badReport.Num                   = details.Sum(o => o.Num);
                _context.Entry(badReport).State = EntityState.Modified;
                var _details = await _context.BadReportDetail.Where(o => o.OrderNum == badReport.OrderNum).ToListAsync();

                foreach (var _detail in _details)
                {
                    var detail = details.FirstOrDefault(o => o.ProductNum == _detail.ProductNum &&
                                                        o.FromLocalNum == _detail.FromLocalNum);
                    if (detail == null)
                    {
                        _context.BadReportDetail.Remove(_detail);
                    }
                }

                foreach (var detail in details)
                {
                    var _detail = _details.FirstOrDefault(o => o.ProductNum == detail.ProductNum &&
                                                          o.FromLocalNum == detail.FromLocalNum);
                    if (_detail != null)
                    {
                        _detail.Num = detail.Num;
                    }
                    else
                    {
                        var entry = Mapper.Map <BadReportDetail>(detail);
                        entry.OrderNum   = badReport.OrderNum;
                        entry.CreateTime = DateTime.Now;
                        entry.BarCode    = entry.BarCode;
                        entry.SnNum      = Guid.NewGuid().ToString("N");
                        entry.Num        = detail.Num;
                        await _context.BadReportDetail.AddAsync(entry);
                    }
                }
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
        public async Task <ServiceResponseBase> Update(SupplierViewModel vm, AccountViewModel account)
        {
            try
            {
                var isExist = await _context.Supplier.AnyAsync(o => o.SupName == vm.SupName &&
                                                               o.CompanyId == account.CompanyId && o.Id != vm.Id);

                if (isExist)
                {
                    return(new ServiceResponseBase()
                    {
                        Status = Status.error, Message = "存在重复供应商"
                    });
                }
                var supplier = await _context.Supplier.FirstOrDefaultAsync(o => o.Id == vm.Id);

                Mapper.Map(vm, supplier);
                _context.Entry(supplier).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
Esempio n. 4
0
        public async Task <ServiceResponseBase> Update(MeasureViewModel vm, AccountViewModel account)
        {
            try
            {
                var isExist = await _context.Measure.AnyAsync(o => o.MeasureName == vm.MeasureName &&
                                                              o.CompanyId == account.CompanyId && o.Id != vm.Id);

                if (isExist)
                {
                    return(new ServiceResponseBase()
                    {
                        Status = Status.error, Message = "存在重复名称"
                    });
                }
                var measure = await _context.Measure.FirstOrDefaultAsync(o => o.Id == vm.Id);

                Mapper.Map(vm, measure);
                measure.MeasureNum            = "";
                measure.Sn                    = "";
                _context.Entry(measure).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
        public async Task <ServiceResponseBase> Update(CheckStockViewModel vm, AccountViewModel account)
        {
            try
            {
                var checkStock = await _context.CheckStock.FirstOrDefaultAsync(o => o.Id == vm.Id);

                Mapper.Map(vm, checkStock);
                _context.Entry(checkStock).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
Esempio n. 6
0
        public async Task <ServiceResponseBase> Update(LocationViewModel vm, AccountViewModel account)
        {
            try
            {
                var isExist = await _context.Location.AnyAsync(o => o.LocalBarCode == vm.LocalBarCode &&
                                                               o.CompanyId == account.CompanyId && o.Id != vm.Id);

                if (isExist)
                {
                    return(new ServiceResponseBase()
                    {
                        Status = Status.error, Message = "存在重复条码"
                    });
                }
                var location = await _context.Location.FirstOrDefaultAsync(o => o.Id == vm.Id);

                Mapper.Map(vm, location);
                location.Rack                  = "";
                location.Length                = 0;
                location.Width                 = 0;
                location.Height                = 0;
                location.X                     = 0;
                location.Y                     = 0;
                location.Z                     = 0;
                location.UnitNum               = "";
                location.UnitName              = "";
                location.StorageNum            = location.BranchId.ToString();
                _context.Entry(location).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
        public async Task <ServiceResponseBase> Update(InStorageViewModel vm, List <InStorDetailViewModel> inStorDetails, AccountViewModel account)
        {
            try
            {
                var inStorage = await _context.InStorage.FirstOrDefaultAsync(o => o.Id == vm.Id);

                inStorage.InType = vm.InType;
                inStorage.SupNum = vm.SupNum;
                var supId = Convert.ToInt32(vm.SupNum);
                var sup   = await _context.Supplier.FirstOrDefaultAsync(o => o.Id == supId);

                inStorage.SupName     = sup.SupName;
                inStorage.ContactName = vm.ContactName;
                inStorage.Phone       = vm.Phone;
                inStorage.Remark      = vm.Remark;
                var status = (InOpStatus)inStorage.Status;
                if (status == InOpStatus.待入库)
                {
                    inStorage.Num = inStorDetails.Sum(o => o.Num);
                }
                _context.Entry(inStorage).State = EntityState.Modified;
                var _inStorDetails = await _context.InStorDetail.Where(o => o.OrderNum == inStorage.OrderNum).ToListAsync();

                foreach (var _inStorDetail in _inStorDetails)
                {
                    var inStorDetail = inStorDetails.FirstOrDefault(o => o.ProductNum == _inStorDetail.ProductNum &&
                                                                    o.LocalNum == _inStorDetail.LocalNum);
                    if (inStorDetail == null)
                    {
                        _context.InStorDetail.Remove(_inStorDetail);
                    }
                }

                foreach (var inStorDetail in inStorDetails)
                {
                    var _inStorDetail = _inStorDetails.FirstOrDefault(o => o.ProductNum == inStorDetail.ProductNum &&
                                                                      o.LocalNum == inStorDetail.LocalNum);
                    if (_inStorDetail != null)
                    {
                        if (status == InOpStatus.待入库)
                        {
                            _inStorDetail.Num = inStorDetail.Num;
                        }
                        if (status == InOpStatus.已入库)
                        {
                            _inStorDetail.RealNum = inStorDetail.Num;
                        }
                        if (status == InOpStatus.已上架)
                        {
                            _inStorDetail.PutRealNum = inStorDetail.Num;
                        }
                        _inStorDetail.InPrice = inStorDetail.InPrice;
                    }
                    else
                    {
                        var entry = Mapper.Map <InStorDetail>(inStorDetail);
                        entry.OrderNum   = inStorage.OrderNum;
                        entry.CreateTime = DateTime.Now;
                        entry.BarCode    = entry.ProductNum;
                        entry.SnNum      = Guid.NewGuid().ToString("N");
                        if (status == InOpStatus.待入库)
                        {
                            entry.Num = inStorDetail.Num;
                        }
                        if (status == InOpStatus.已入库)
                        {
                            entry.RealNum = inStorDetail.Num;
                        }
                        if (status == InOpStatus.已上架)
                        {
                            entry.PutRealNum = inStorDetail.Num;
                        }
                        await _context.InStorDetail.AddAsync(entry);
                    }
                }
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }
        public async Task <ServiceResponseBase> Update(OutStorageViewModel vm, List <OutStoDetailViewModel> outStorDetails, AccountViewModel account)
        {
            try
            {
                var outStorage = await _context.OutStorage.FirstOrDefaultAsync(o => o.Id == vm.Id);

                outStorage.OutType = vm.OutType;
                outStorage.CusNum  = vm.CusNum;
                outStorage.CusName = vm.CusName;
                outStorage.Contact = vm.Contact;
                outStorage.Phone   = vm.Phone;
                outStorage.Remark  = vm.Remark;
                var cusId = Convert.ToInt32(vm.CusNum);
                var cus   = _context.Customer.FirstOrDefault(o => o.Id == cusId);
                outStorage.CusName = cus.CusName;
                var status = (OutOpStatus)outStorage.Status;
                if (status == OutOpStatus.待下架)
                {
                    outStorage.Num = outStorDetails.Sum(o => o.Num);
                }
                _context.Entry(outStorage).State = EntityState.Modified;
                var _outStorDetails = await _context.OutStoDetail.Where(o => o.OrderNum == outStorage.OrderNum).ToListAsync();

                foreach (var _outStorDetail in _outStorDetails)
                {
                    var outStorDetail = outStorDetails.FirstOrDefault(o => o.ProductNum == _outStorDetail.ProductNum &&
                                                                      o.LocalNum == _outStorDetail.LocalNum);
                    if (outStorDetail == null)
                    {
                        _context.OutStoDetail.Remove(_outStorDetail);
                    }
                }

                foreach (var outStorDetail in outStorDetails)
                {
                    var _outStorDetail = _outStorDetails.FirstOrDefault(o => o.ProductNum == outStorDetail.ProductNum &&
                                                                        o.LocalNum == outStorDetail.LocalNum);
                    if (_outStorDetail != null)
                    {
                        if (status == OutOpStatus.待下架)
                        {
                            _outStorDetail.Num = outStorDetail.Num;
                        }
                        if (status == OutOpStatus.已下架)
                        {
                            _outStorDetail.RealNum = outStorDetail.Num;
                        }
                        if (status == OutOpStatus.已出库)
                        {
                            _outStorDetail.PutRealNum = outStorDetail.Num;
                        }
                        _outStorDetail.OutPrice = outStorDetail.OutPrice;
                    }
                    else
                    {
                        var entry = Mapper.Map <OutStoDetail>(outStorDetail);
                        entry.OrderNum   = outStorage.OrderNum;
                        entry.CreateTime = DateTime.Now;
                        entry.BarCode    = entry.BarCode;
                        entry.SnNum      = Guid.NewGuid().ToString("N");
                        if (status == OutOpStatus.待下架)
                        {
                            entry.Num = outStorDetail.Num;
                        }
                        if (status == OutOpStatus.已下架)
                        {
                            entry.RealNum = outStorDetail.Num;
                        }
                        if (status == OutOpStatus.已出库)
                        {
                            entry.PutRealNum = outStorDetail.Num;
                        }
                        await _context.OutStoDetail.AddAsync(entry);
                    }
                }
                await _context.SaveChangesAsync();

                return(new ServiceResponseBase()
                {
                    Status = Status.ok
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                return(new ServiceResponseBase()
                {
                    Status = Status.error, Message = ex.Message
                });
            }
        }