public async Task CreateAsync([FromBody] Inventory employee)
 {
     if (ModelState.IsValid)
     {
         await _iInventoryRepository.Add(employee);
     }
 }
Esempio n. 2
0
        public async Task <Result <int> > Add(InventoryDTO inventory)
        {
            try
            {
                if (inventory.Id > 0)
                {
                    return(Result.Fail <int>("Inventory id should be zero while adding"));
                }
                var validate = ValidateInventory(inventory);
                if (!validate.Value)
                {
                    return(Result.Fail <int>(validate.GetErrorString()));
                }
                var inv    = inventory.GetInventory();
                var result = await _repository.Add(inv.BaseMap());

                if (result.Id > 0)
                {
                    return(Result.Ok(result.Id));
                }
                else
                {
                    return(Result.Fail <int>("Failed to add inventory"));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(Result.Fail <int>("Failed to add inventory"));
            }
        }
        public async Task AddInventory(Guid productId, int quantity, CancellationToken cancellationToken)
        {
            var product = await productRepository.Get(e => e.Id.Equals(productId), cancellationToken)
                          ?? throw new NotFoundException("Não foi possível adicionar o produto!");

            var inventory = new Inventory(product, quantity);

            await inventoryRepository.Add(inventory, cancellationToken);
        }
Esempio n. 4
0
        public void CreateInventory(IData data)
        {
            var inventoryData = data as InventoryData;

            _inventoryRepository.Add(
                Inventory.Create(inventoryData?.Name, inventoryData?.Description));

            _inventoryRepository.UnitOfWork.Commit();
        }
Esempio n. 5
0
        private void InitializeInventory(Product product)
        {
            Inventory inventory = new Inventory();

            inventory.Product  = product;
            inventory.Id       = Guid.NewGuid();
            inventory.Quantity = 0;
            _inventoryRepository.Add(inventory);
        }
        public void Save(Inventory inventory)
        {
            var inv = inventoryContext.Get(inventory.Id);

            if (inv == null)
            {
                inventoryContext.Add(inventory);
                inventoryContext.Commit();
            }
        }
Esempio n. 7
0
        public async Task Handle(ProductCreatedDomainEvent notification, CancellationToken cancellationToken)
        {
            int initialStock = 0;
            var newInventory = new Inventory(initialStock, notification.ProductId);

            _inventoryRepository.Add(newInventory);

            _logger.CreateLogger("----- Creating Inventory - iventory");

            await _inventoryRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
        }
        public async Task <bool> Handle(CreateItemCommand message, CancellationToken cancellationToken)
        {
            var inventory = new Inventory(message.ProductName, message.ProductSize);

            inventory.AddInventoryItem(new InventoryItem()
            {
                Type = "thimbdrive"
            });
            _inventoryRepository.Add(inventory);

            return(await _inventoryRepository.UnitOfWork
                   .SaveEntitiesAsync(cancellationToken));
        }
 private void Add(Product product, bool checkAddCodes)
 {
     if (null == product)
     {
         throw new Exception("A product must be provided");
     }
     inventoryRepository.Add(product);
     if (checkAddCodes)
     {
         List <Category>   existingCategories  = categoryRepository.Fetch();
         List <Contract>   existingContracts   = contractRepository.Fetch(0, int.MaxValue);
         List <Contractor> existingContractors = contractorRepository.Fetch(0, int.MaxValue);
         AddCategory(existingCategories, product.Category, product.ProductType);
         AddContract(existingContracts, product.ContractNumber);
         AddContractor(existingContractors, product.Contractor);
     }
 }
Esempio n. 10
0
        public IHttpActionResult PostInventory(InventoriesModel inventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbInventory = new Inventory();

            _inventoryRepository.Add(dbInventory);

            _unitOfWork.Commit();

            inventory.InventoryId = dbInventory.InventoryId;

            return(CreatedAtRoute("DefaultApi", new { id = inventory.InventoryId }, inventory));
        }
Esempio n. 11
0
        public Response Add(DeliveryDto deliveryDto)
        {
            Response response = new Response();

            try
            {
                var model = _mapper.Map <Delivery>(deliveryDto);
                _inventoryRepository.Add(model);
                response.Message = "ثبت با موفقیت انجام شد";
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Errors    = new Error("", "خطا در ثبت اطلاعات");
            }
            return(response);
        }
Esempio n. 12
0
        public async Task <IActionResult> CreateItem(ItemForDetailDto itemForDetailDto)
        {
            var itemToCreate = _mapper.Map <Item>(itemForDetailDto);

            itemToCreate.ItemCategory = await _invRepo.Get <ItemCategory>(itemForDetailDto.ItemCategory.Id);

            itemToCreate.Unit = await _invRepo.Get <Unit>(itemForDetailDto.Unit.Id);

            _invRepo.Add <Item>(itemToCreate);

            if (await _invRepo.SaveAll())
            {
                return(Ok());
            }

            throw new System.Exception($"Failed to Create item on save");
        }
Esempio n. 13
0
        public async Task <IActionResult> CreateSupplier(SupplierDto supplierDto)
        {
            var supTOCreate = _mapper.Map <Supplier>(supplierDto);

            if (await _context.Suppliers.AnyAsync(a => a.Name == supTOCreate.Name))
            {
                return(BadRequest("Supplier already exist"));
            }

            _invRepo.Add <Supplier>(supTOCreate);

            if (await _invRepo.SaveAll())
            {
                return(Ok());
            }

            throw new System.Exception($"Failed to Create Supplier on save");
        }
Esempio n. 14
0
        /// <summary>
        /// 资产盘点计划
        /// </summary>
        /// <param name="item"></param>
        public void AddAssetsInventoryPlan(InventoryAttribute item)
        {
            _inventoryRep.Add(item);
            var details = new List <InventoryDetailAttribute>();
            var assets  = _assetsService.Get(item.AssetsNums);

            foreach (var asset in assets)
            {
                details.Add(new InventoryDetailAttribute
                {
                    InventoryFormNo = item.EntityId,
                    AssetsNo        = asset.AssetsNum,
                    UsedNum1        = asset.UsedNum1,
                    InventoryPerson = item.InventoryPerson,
                    InventoryDate   = item.InventoryDate
                });
            }
            _inventoryDetailRep.Add(details);
        }
Esempio n. 15
0
        public async Task <IActionResult> CreateUnit(UnitForDetailDto unitForDetailDto)
        {
            if (await _context.Units.AnyAsync(a => a.Description == unitForDetailDto.Description))
            {
                return(BadRequest("Unit Exist"));
            }

            Unit unitToCreate = new Unit();

            unitToCreate.Description = unitForDetailDto.Description;

            _invRepo.Add <Unit>(unitToCreate);

            if (await _invRepo.SaveAll())
            {
                return(Ok());
            }

            throw new System.Exception($"Failed to Create unit on save");
        }
        public async Task Post_WithRequest_ReturnsResult()
        {
            var productId = 1;
            var quantity  = 2;
            InventoryPostRequest request = new InventoryPostRequest {
                Quantity = quantity
            };
            InventoryResponse inventoryResponse = new InventoryResponse {
                ProductId = productId, Quantity = quantity
            };

            var expectedObjectResult = new OkObjectResult(inventoryResponse);

            _inventoryRepository.Add(quantity).Returns(inventoryResponse);

            var sut = CreateSut();

            var actual = sut.Post(request);

            actual.As <OkObjectResult>().Should().BeEquivalentTo(expectedObjectResult);
        }
        public async Task <IActionResult> CreateItemCategory(ItemCategoryForDetailDto itemCategoryForDetailDto)
        {
            if (await _context.ItemCategories.AnyAsync(a => a.Code == itemCategoryForDetailDto.Code))
            {
                return(BadRequest("item Category Exist"));
            }

            ItemCategory catToCreate = new ItemCategory();

            catToCreate.Code        = itemCategoryForDetailDto.Code.ToUpper();
            catToCreate.Description = itemCategoryForDetailDto.Description;

            _invRepo.Add <ItemCategory>(catToCreate);

            if (await _invRepo.SaveAll())
            {
                return(Ok());
            }

            throw new System.Exception($"Failed to Create Item category on save");
        }
Esempio n. 18
0
        public async Task <IActionResult> ShopBuy(int id)
        {
            var user = await _userManager.GetUserAsync(User);

            var item = _itemRepository.GetItem(id);

            if (item == null)
            {
                ViewBag.ErrorMessage = $"Nie można znaleźć przedmiotu o Id: '{id}'.";
                return(View("NotFound"));
            }

            var inventory = _inventoryRepository.GetInventory(user.Id);

            if (inventory.Count() > 13)
            {
                ModelState.AddModelError(string.Empty, "Nie pomieścisz już więcej w plecaku.");
            }
            else if (item.Cost > user.Gold)
            {
                ModelState.AddModelError(string.Empty, "Nie masz wystarczającej ilości złota.");
            }
            else
            {
                user.Gold -= item.Cost;
                await _userManager.UpdateAsync(user);

                _inventoryRepository.Add(new Inventory()
                {
                    ItemId = item.Id,
                    UserId = user.Id
                });
            }

            return(RedirectToAction("WeaponShop"));
        }
 public override void Add(InventoryItem entity)
 {
     _inventoryRepository.Add(entity);
 }
 public void Add(Inventory entity)
 {
     inventoryRepository.Add(entity);
     SaveChanges();
 }
Esempio n. 21
0
        public IActionResult Post(InventoryPostRequest request)
        {
            var inventoryResponse = _inventoryRepository.Add(request.Quantity);

            return(Ok(inventoryResponse));
        }
 public async Task <bool> Add(Book book)
 {
     return(await _repo.Add(book));
 }
        public async Task <IActionResult> CreatePurchaseOrder(POHForDetailDto pOHForDetailDto, [FromQuery] bool isForSending)
        {
            if (pOHForDetailDto == null)
            {
                return(BadRequest("Empty Body"));
            }

            var pOHToCreate = _mapper.Map <PurchaseOrderHeader>(pOHForDetailDto);

            if (User.FindAll(ClaimTypes.Role).Any(a => a.Value == "Admin"))
            {
                pOHToCreate.isFromOutlet = pOHForDetailDto.isForOutlet;
            }
            else
            {
                pOHToCreate.isFromOutlet = User.FindAll(ClaimTypes.Role).Any(a => a.Value == "OutletManager") ? true : false;
            }

            pOHToCreate.Status = 0;
            // pOHToCreate.Supplier = await _repository.GetSupplier(pOHForDetailDto.SupplierId);

            await _repository.CreatePurchaseOrder(pOHToCreate);

            if (await _repository.SaveAll())
            {
                //sending mail
                var filterParams = GetFilterParams();

                var pOHFromRepository = await _repository.GetPurchaseOrder(pOHToCreate.Id, filterParams);

                if (isForSending)
                {
                    var htmlBody = GenerateMailHtml(pOHFromRepository.PONumber, User.FindAll(ClaimTypes.Name).FirstOrDefault().ToString(),
                                                    pOHFromRepository.Supplier.Name, pOHFromRepository.DeliveryMethod, pOHFromRepository.OrderDate,
                                                    pOHFromRepository.DeliveryDate, pOHFromRepository.PurchaseOrderDetail);

                    if (await SendMail("*****@*****.**", "*****@*****.**", "Purchase Order From Upland Bake house",
                                       htmlBody, "*****@*****.**", "hell123boy"))
                    {
                        pOHFromRepository.Status = 1;
                    }
                    else
                    {
                        var supFromRepo = pOHFromRepository.Supplier;
                        pOHFromRepository.Status = 1;
                        Notification noti = new Notification
                        {
                            Title   = "Purchase Order No " + pOHFromRepository.PONumber + " Failed To send",
                            Message = "purchase Order No "
                                      + pOHFromRepository.PONumber
                                      + " Failed To send , Supplier Detail are as Follows "
                                      + " Supplier Name  "
                                      + supFromRepo.Name
                                      + " Supplier Contact "
                                      + supFromRepo.ContactNumber
                                      + " Supplier email "
                                      + supFromRepo.Email
                                      + " Supplier Address "
                                      + supFromRepo.Address,
                            DateTime = DateTime.Now,
                            UserId   = pOHFromRepository.UserId,
                            Status   = 0
                        };

                        _repository.Add(noti);
                    }
                }

                if (isForSending == true && pOHFromRepository.Status == 0)
                {
                    return(Ok(new { error = "Failed to send" }));
                }

                await _repository.SaveAll();

                var pOHtoReturn = _mapper.Map <POHForDetailDto>(pOHToCreate);
                return(CreatedAtRoute(nameof(GetPurchaseOrder), new { pOHToCreate.Id }, pOHtoReturn));
            }

            return(BadRequest("Could not create Purchase Order"));
        }
Esempio n. 24
0
 public void AddAssetsInventory(InventoryAttribute item)
 {
     _assetsInventoryRep.Add(item);
 }
Esempio n. 25
0
 /// <summary>
 /// Adds item to inventory.
 /// </summary>
 /// <param name="item">IInventoryItem to be added.</param>
 /// <returns>IInventoryItem that was added. To support fluent code style.</returns>
 public IInventoryItem Add(IInventoryItem item)
 {
     return(_repository.Add(item));
 }
Esempio n. 26
0
        public async Task <IActionResult> CreateInventory([FromBody] InventoryCreateDto inventoryCreate)
        {
            if (inventoryCreate == null)
            {
                return(BadRequest(new { error = new string[] { "Invalid Form Data sent to the server " } }));
            }

            if (string.IsNullOrEmpty(inventoryCreate.Product))
            {
                return(BadRequest(new { error = "Product Name is Required" }));
            }

            if (string.IsNullOrEmpty(inventoryCreate.Location))
            {
                return(BadRequest(new { error = "Location Name is Required" }));
            }


            var product = await _productRepo.GetProductByName(inventoryCreate.Product);

            if (product == null)
            {
                ModelState.AddModelError("error", "Product Not Found");
            }

            var location = await _locationRepo.GetLocationByName(inventoryCreate.Location);

            if (location == null)
            {
                ModelState.AddModelError("error", "Location not Found");
            }

            var status = await _invRepo.GetInventoryStatusByName("No Stock");

            if (status == null)
            {
                ModelState.AddModelError("error", "Status Not Found");
            }

            if (string.IsNullOrEmpty(inventoryCreate.Sku))
            {
                ModelState.AddModelError("error", "SKU is Required");
            }
            else
            {
                //Check if SKU is existing
                var inventoryBySku = await _invRepo.GetInventoryBySku(inventoryCreate.Sku);

                //IF SKU is not existing - update the sku. Else return Error that SKU already exist.
                //This means that the combination of Product and Location already exist.
                if (inventoryBySku != null)
                {
                    ModelState.AddModelError("error", "SKU Already Exist");
                }
            }

            if (inventoryCreate.ThresholdCritical >= inventoryCreate.ThresholdWarning)
            {
                ModelState.AddModelError("error", "Critical should be less than Warning");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            Inventory newIventory = new Inventory
            {
                Sku               = inventoryCreate.Sku,
                Quantity          = 0,
                ThresholdWarning  = inventoryCreate.ThresholdWarning,
                ThresholdCritical = inventoryCreate.ThresholdCritical,
                Product           = product,
                Location          = location,
                Status            = status
            };

            _invRepo.Add(newIventory);

            if (await _invRepo.Save())
            {
                var invetoryToReturn = _mapper.Map <InventoryDetailDto>(newIventory);

                return(CreatedAtRoute(new { controller = "inventories", id = newIventory.Id }, invetoryToReturn));
            }

            return(BadRequest(new { error = "Error creating inventory" }));
        }