public long Add(Warehouse obj) { //var customer = _customerService.GetByDomain(obj.); if (IsDuplicate(obj.WarehouseCode, obj.Id, obj.CustomerId) == false) { return(_warehouseRepository.Add(obj)); } else { Expression <Func <Warehouse, bool> > res = x => x.WarehouseCode == obj.WarehouseCode && x.CustomerId == obj.CustomerId && x.IsActive == false; var model = _warehouseRepository.Get(res); if (model != null) { obj.Id = model.Id; obj.IsActive = true; _warehouseRepository.Detach(model); _warehouseRepository.Update(obj); return(obj.Id); } else { return(0); } } }
public void Add(Warehouse warehouse) { repository.Add(warehouse); //Go to AssetOwnerRepository and add a new Owner by adding the Person(ID) repositoryAssetOwner.AddAssetOwnerWarehouse(warehouse.WarehouseID); //no need to return anyting, that's why here keep void! }
public JsonResult SaveRepository([CustomizeValidator] WarehouseDto m) { var q = new Repositorys() { Id = m.Id, Name = m.Name, Address = m.Address }; return(Json <string>(_warehouseRepository.Add(q), "保存成功!")); }
public IActionResult Post([FromBody] WarehouseDto model) { try { return(Ok( warehouseRepository.Add(new Warehouse() { Name = model.Name, Descripcion = model.Description, Location = model.Location }) )); } catch (Exception e) { throw e; } }
public async Task <IActionResult> PostStockItemAsync([FromBody] PostStockItemsRequest request) { Logger?.LogDebug("'{0}' has been invoked", nameof(PostStockItemAsync)); var response = new SingleResponse <StockItem>(); try { var existingEntity = await Repository .GetStockItemsByStockItemNameAsync(new StockItem { StockItemName = request.StockItemName }); if (existingEntity != null) { ModelState.AddModelError("StockItemName", "Stock item name already exists"); } if (!ModelState.IsValid) { return(BadRequest()); } // Create entity from request model var entity = request.ToEntity(); // Add entity to repository Repository.Add(entity); // Save entity in database await Repository.CommitChangesAsync(); // Set the entity to response model response.Model = entity; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "There was an internal error, please contact to technical support."; Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(PostStockItemAsync), ex); } return(response.ToHttpResponse()); }
public async Task <IActionResult> NewStock(WarehouseViewModel model) { if (ModelState.IsValid) { var stock = new Warehouse { ItemName = model.ItemName, TotalInSotck = model.TotalInSotck }; warehouse.Add(stock); await warehouse.SaveAsync(stock); ViewBag.Addded = "New stock added successfully"; ModelState.Clear(); return(View(model)); } return(View()); }
public async Task <WarehouseDto> CreateAsync(WarehouseDto warehouseDto) { if (warehouseDto == null) { throw new ArgumentNullException(nameof(warehouseDto)); } var existingWarehouse = await _warehouseRepository.FilterAsync(x => x.Name == warehouseDto.Name && x.Company.Id == warehouseDto.Company.Id); if (existingWarehouse.Count != 0) { throw new Exception("Warehouse with same name already exists."); } var warehouse = _mapper.Map <WarehouseDto, Warehouse>(warehouseDto); _warehouseRepository.Add(warehouse); await _warehouseRepository.SaveChangesAsync(); return(_mapper.Map <Warehouse, WarehouseDto>(warehouse)); }
public Product Map(ProductViewModel productViewModel) { if (productViewModel == null) { return(null); } List <Inventory> inventory = new List <Inventory>(); Product product = new Product(productViewModel.Sku, productViewModel.Name, inventory); foreach (var warehouseViewModel in productViewModel.Inventory.Warehouses) { var warehouse = warehouseRepository.Get(warehouseViewModel.Locality, warehouseViewModel.Type.ToString()); if (warehouse == null) { warehouse = new Warehouse(warehouseViewModel.Locality, warehouseViewModel.Type); warehouseRepository.Add(warehouse); } inventory.Add(new Inventory(product.Id, warehouse.Id, warehouseViewModel.Quantity)); } return(product); }
public async Task <IActionResult> AddOrder(string line, int id, ReferenceToAddOrderDto referenceToAddOrder, [FromQuery] int repeatAmount) { var currentUser = await userManager.FindByIdAsync(id.ToString()); var order = AdjustReference.CreateNewOrder(referenceToAddOrder.Reference); if (order.Reference == null) { return(BadRequest("Podana referencja jest nieprawidłowa")); } order.Status = "Nowe"; order.Line = currentUser.UserName; order.Amount = referenceToAddOrder.Amount; var orders = await warehouseRepository.GetOrders(line); for (int j = 0; j < repeatAmount; j++) { var position = orders.Select(o => o.Position).ToList(); //If entered position is greater than zero, all other orders positions add plus one. if (referenceToAddOrder.Position > 0) { var positionToCheck = position.Where(p => p >= referenceToAddOrder.Position).ToList(); for (int i = 0; i < positionToCheck.Count(); i++) { var currentPosition = orders.Where(o => o.Position == positionToCheck[i]).LastOrDefault(); currentPosition.Position += 1; } //Add to new position entered position and current j value. order.Position = referenceToAddOrder.Position + j; } else { var positionToCheck = position.FirstOrDefault(); //If orders have any data, then new position is equal last position + 1 (and current j value). if (positionToCheck > 0) { var positionToAdd = position.OrderByDescending(p => p).FirstOrDefault(); order.Position = positionToAdd + 1 + j; } else { order.Position = 1 + j; } } var newOrder = mapper.Map <Plan>(order); warehouseRepository.Add(newOrder); } if (await warehouseRepository.SaveAll()) { return(Ok()); } return(BadRequest("Nie udało się dodać zamówienia.")); }
public int PostWarehouse(WarehouseInputDTO item) { return(repository.Add(item)); }
public Warehouse Add(Warehouse warehouse) { return(_warehouseRepository.Add(warehouse)); }
public ApiResponseBase Put([FromBody] ApiWarehouse product) { _repo.Add(product); return(new ApiResponseBase()); }
public async Task <IActionResult> Post([FromBody] WarehouseItemDto warehouseItem) { await _warehouseRepository.Add(WarehouseMapper.MapToWarehouseItem(warehouseItem)); return(Ok()); }
public void CreateWarehouse(Warehouse warehouse) { warehouseRepository.Add(warehouse); }