Ejemplo n.º 1
0
        public async Task <SimpleResult> SaveMaterial(MaterialViewModel input)
        {
            try
            {
                var objParam = new MaterialPoco
                {
                    Cost             = input.UnitCostPrice,
                    Id               = input.Id,
                    StockCode        = input.StockCode,
                    StockDescription = input.StockDescription
                };
                var result = await _material.SaveMaterial(objParam);

                return(new SimpleResult
                {
                    IsSuccess = result.IsSuccess,
                    ErrorMessage = result.ErrorMessage,
                    Id = result.Id
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(new SimpleResult
                {
                    IsSuccess = false
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <SimpleResultPoco> SaveMaterial(MaterialPoco input)
        {
            await _context.Materials.AddAsync(input);

            var id = await _context.SaveChangesAsync();

            return(new SimpleResultPoco
            {
                IsSuccess = true,
                Id = Convert.ToInt64(id)
            });
        }
Ejemplo n.º 3
0
        public async Task <SimpleResult> SaveMaterials(UploadInventoryViewModel input)
        {
            try
            {
                var warehouse = await _context.Warehouses.FindAsync(input.WarehousesId);

                var existingInventory = warehouse.Inventory;
                if (existingInventory != null)
                {
                    _context.Inventories.RemoveRange(existingInventory);
                    await _context.SaveChangesAsync();
                }
                var newInventory = new List <InventoryPoco>();
                foreach (var inv in input.Inventory)
                {
                    var mat = _context.Materials.Where(x => x.StockCode == inv.StockCode).FirstOrDefault();
                    if (mat == null)
                    {
                        var material = new MaterialPoco
                        {
                            Cost             = Convert.ToDecimal(inv.Cost, CultureInfo.InvariantCulture),
                            StockCode        = inv.StockCode,
                            StockDescription = inv.StockDescription
                        };
                        _context.Materials.Add(material);
                        _context.SaveChanges();
                        var inventory = new InventoryPoco
                        {
                            DateAdded    = DateTime.Now,
                            DateModified = DateTime.Now,
                            Deleted      = false,
                            MaterialId   = material.Id,
                            ModifiedBy   = "",
                            Quantity     = Convert.ToDecimal(inv.Quantity, CultureInfo.InvariantCulture),
                            WarehouseId  = input.WarehousesId
                        };
                        newInventory.Add(inventory);
                    }
                    else
                    {
                        var inventory = new InventoryPoco
                        {
                            DateAdded    = DateTime.Now,
                            DateModified = DateTime.Now,
                            Deleted      = false,
                            MaterialId   = mat.Id,
                            ModifiedBy   = "",
                            Quantity     = Convert.ToDecimal(inv.Quantity, CultureInfo.InvariantCulture),
                            WarehouseId  = input.WarehousesId
                        };
                        newInventory.Add(inventory);
                    }
                }
                await _context.AddRangeAsync(newInventory);

                await _context.SaveChangesAsync();

                return(new SimpleResult
                {
                    IsSuccess = true
                });
            }
            catch
            {
                return(new SimpleResult
                {
                    IsSuccess = false
                });
            }
        }