public Locations CreateLocation(Locations location, List <int> productIds, int userId, int tenantId,
                                 int warehouseId)
 {
     location.CreatedBy   = userId;
     location.DateCreated = DateTime.UtcNow;
     location.TenentId    = tenantId;
     location.WarehouseId = warehouseId;
     _currentDbContext.Locations.Add(location);
     _currentDbContext.SaveChanges();
     if (productIds != null)
     {
         foreach (var item in productIds)
         {
             ProductLocations locMap = new ProductLocations
             {
                 CreatedBy   = userId,
                 DateCreated = DateTime.UtcNow,
                 LocationId  = location.LocationId,
                 ProductId   = item,
                 TenantId    = tenantId,
             };
             _currentDbContext.ProductLocationsMap.Add(locMap);
         }
         _currentDbContext.SaveChanges();
     }
     return(location);
 }
Exemple #2
0
        public Locations SaveProductLocation(Locations model, int warehouseId, int tenantId, int userId, int productId = 0)
        {
            if (model.LocationId < 1)
            {
                var cLocation =
                    _currentDbContext.Locations.FirstOrDefault(a => a.WarehouseId == warehouseId &&
                                                               a.TenentId == tenantId && a.LocationCode ==
                                                               model.LocationCode);
                if (cLocation != null)
                {
                    throw new Exception("Location Code already exists!");
                }
                model.IsActive  = true;
                model.IsDeleted = false;
                model.TenentId  = tenantId;

                model.DateUpdated = DateTime.UtcNow;
                model.DateCreated = DateTime.UtcNow;
                model.CreatedBy   = userId;
                model.UpdatedBy   = userId;

                model.WarehouseId = warehouseId;

                _currentDbContext.Entry(model).State = EntityState.Added;
                _currentDbContext.SaveChanges();

                if (productId > 0)
                {
                    var map = new ProductLocations
                    {
                        LocationId  = model.LocationId,
                        ProductId   = productId,
                        TenantId    = tenantId,
                        DateCreated = DateTime.UtcNow,
                        CreatedBy   = userId
                    };
                    _currentDbContext.ProductLocationsMap.Add(map);
                }
            }
            else
            {
                var cLocation =
                    _currentDbContext.Locations.AsNoTracking().FirstOrDefault(a => a.WarehouseId == warehouseId &&
                                                                              a.TenentId == tenantId && a.LocationCode ==
                                                                              model.LocationCode);

                model.UpdatedBy   = userId;
                model.DateUpdated = DateTime.UtcNow;
                model.DateCreated = cLocation.DateCreated;
                model.WarehouseId = cLocation.WarehouseId;
                model.TenentId    = cLocation.TenentId;
                model.CreatedBy   = cLocation.CreatedBy;
                model.IsActive    = cLocation.IsActive;
            }

            _currentDbContext.Entry(model).State = EntityState.Modified;
            _currentDbContext.SaveChanges();
            return(model);
        }
        public Locations BulkCreateProductsLocation(Locations location, List <int> productIds, int?startValue,
                                                    int?endValue, int tenantId,
                                                    int warehouseId, int userId)
        {
            var code = location.LocationCode;
            var name = location.LocationName;

            for (var ctr = startValue; ctr <= endValue; ctr++)
            {
                var obj = location;
                obj.CreatedBy    = userId;
                obj.TenentId     = tenantId;
                obj.WarehouseId  = warehouseId;
                obj.DateCreated  = DateTime.UtcNow;
                obj.LocationCode = code + ctr;
                obj.LocationName = name + ctr;
                obj.PickSeq      = location.PickSeq != null ? ctr : null;
                obj.PutAwaySeq   = location.PutAwaySeq != null ? ctr : null;
                obj.ReplenishSeq = location.ReplenishSeq != null ? ctr : null;
                _currentDbContext.Locations.Add(obj);
                _currentDbContext.SaveChanges();
                if (productIds != null)
                {
                    foreach (var item in productIds)
                    {
                        var locMap = new ProductLocations
                        {
                            LocationId  = obj.LocationId,
                            CreatedBy   = userId,
                            DateCreated = DateTime.UtcNow,
                            ProductId   = item,
                            TenantId    = tenantId
                        };
                        _currentDbContext.ProductLocationsMap.Add(locMap);
                        _currentDbContext.SaveChanges();
                    }
                }
            }
            return(location);
        }
Exemple #4
0
        public MainWindow()
        {
            ViewContext = SynchronizationContext.Current;

            NGDPPatchHosts  = new NGDPPatchHosts();
            RecentLocations = new RecentLocations();
            ProgressInfo    = new ProgressInfo();
            CASCSettings    = new CASCSettings();
            ProductAgent    = new ProductLocations();

            ProgressSlave.OnProgress += UpdateProgress;

            if (!NGDPPatchHosts.Any(x => x.Active))
            {
                NGDPPatchHosts[0].Active = true;
            }

            InitializeComponent();
            DataContext = this;
            // FolderView.ItemsSource = ;
            // FolderItemList.ItemsSource = ;
        }
        public Locations BulkEditProductsLocation(Locations location, List <int> productIds, int tenantId,
                                                  int warehouseId, int userId)
        {
            _currentDbContext.Locations.Attach(location);
            var entry = _currentDbContext.Entry(location);

            entry.Property(e => e.AllowPick).IsModified      = true;
            entry.Property(e => e.AllowPutAway).IsModified   = true;
            entry.Property(e => e.AllowReplenish).IsModified = true;
            entry.Property(e => e.Description).IsModified    = true;
            entry.Property(e => e.DimensionUOMId).IsModified = true;

            entry.Property(e => e.LocationCode).IsModified    = true;
            entry.Property(e => e.LocationName).IsModified    = true;
            entry.Property(e => e.LocationGroupId).IsModified = true;
            entry.Property(e => e.LocationTypeId).IsModified  = true;
            entry.Property(e => e.LocationWeight).IsModified  = true;
            entry.Property(e => e.LocationWidth).IsModified   = true;
            entry.Property(e => e.MixContainer).IsModified    = true;
            entry.Property(e => e.PickSeq).IsModified         = true;
            entry.Property(e => e.PutAwaySeq).IsModified      = true;
            entry.Property(e => e.ReplenishSeq).IsModified    = true;
            entry.Property(e => e.UOMId).IsModified           = true;
            entry.Property(e => e.StagingLocation).IsModified = true;


            location.DateUpdated = DateTime.UtcNow;
            location.UpdatedBy   = userId;
            location.WarehouseId = warehouseId;
            if (productIds != null)
            {
                var toAdd = productIds.Except(_currentDbContext.ProductLocationsMap
                                              .Where(a => a.IsDeleted != true && a.LocationId == location.LocationId).Select(a => a.ProductId)
                                              .ToList());
                var toDelete = _currentDbContext.ProductLocationsMap
                               .Where(a => a.LocationId == location.LocationId && a.IsDeleted != true).Select(a => a.ProductId)
                               .ToList()
                               .Except(productIds);
                foreach (var item in toAdd)
                {
                    var lmap = new ProductLocations
                    {
                        CreatedBy   = userId,
                        DateCreated = DateTime.UtcNow,
                        ProductId   = item,
                        TenantId    = tenantId,
                        LocationId  = location.LocationId,
                    };
                    _currentDbContext.ProductLocationsMap.Add(lmap);
                }
                foreach (var item in toDelete)
                {
                    var cItem = _currentDbContext.ProductLocationsMap.First(
                        a => a.ProductId == item && a.LocationId == location.LocationId && a.IsDeleted != true);
                    cItem.IsDeleted   = true;
                    cItem.DateUpdated = DateTime.UtcNow;
                    cItem.UpdatedBy   = userId;
                }
            }
            else
            {
                var Plist = _currentDbContext.ProductLocationsMap.Where(a => a.LocationId == location.LocationId)
                            .ToList();
                foreach (var item in Plist)
                {
                    item.IsDeleted   = true;
                    item.UpdatedBy   = userId;
                    item.DateUpdated = DateTime.UtcNow;
                }
            }
            _currentDbContext.SaveChanges();

            return(location);
        }