public IActionResult Save([FromBody] ProductData data) { if (data.Availability <= 0) { return(new JsonResult(new Fault("Product is non available"))); } var productData = new ProductData { Description = data.Description, Availability = data.Availability, Categories = data.Categories //Id = ObjectId.GenerateNewId(), //Address = data.Address, //Items = from item in data.Items // select new OrderItem { SKU = new ObjectId(item.Key), Quantity = item.Value } }; SuppliesRepository repository = new SuppliesRepository(Program.connectionString); repository.SaveProduct(productData); //var ip = this.; return(new JsonResult(new SuccessWithResult <string>(productData.Id.ToString()))); //return new JsonResult(new SuccessWithResult<string>(new ProductResponse().URI=)); }
public IActionResult Save([FromBody] ProductData data) { if (data.Availability <= 0) { return(new JsonResult(new Fault("Product not available"))); } var product = new ProductData() { Id = ObjectId.GenerateNewId(), Availability = data.Availability, Categories = data.Categories, Description = data.Description }; SuppliesRepository repository = new SuppliesRepository(Program.connectionString); repository.SaveProduct(product); /* * Stampa al posto dell'id il DTO con tanto di uri del prodotto */ var productUri = $"http://{{host}}/supplies/GetProductBySKU?sku={product.Id.ToString()}"; return(new JsonResult(new SuccessWithResult <string>(productUri))); }
public IActionResult GetAll(int sku) { SuppliesRepository repository = new SuppliesRepository(Program.connectionString); var products = repository.GetAll(); return(new JsonResult(new SuccessWithResult <IEnumerable <ProductData> >(products))); }
public async Task Handle(OrderCreatedMessage message) { SuppliesRepository repository = new SuppliesRepository(Program.connectionString); foreach (var item in message.Items) { repository.DecreaseAvailability(item.Key, item.Value); } await Task.Yield(); }
public IActionResult GetProductBySKU(string sku) { SuppliesRepository repository = new SuppliesRepository(Program.connectionString); var product = repository.GetById(sku); if (product == null) { return(new JsonResult(new Fault("Product does not exists"))); } return(new JsonResult(new SuccessWithResult <ProductData>(product))); }
public UnitOfWork(BuildingDbContext context, ILoggedInUserService loggedInUserService) { _context = context; Projects = new ProjectRepository(_context); Suppliess = new SuppliesRepository(_context); Buildings = new BuildingRepository(_context); BuildingOuts = new BuildingOutRepository(_context); Components = new ComponentRepository(_context); OutbuildingType = new OutbuildingsTypeRepository(_context); Attachments = new AttachmentRepository(_context); AttachmentContents = new AttachmentContentRepository(_context); _loggedInUserService = loggedInUserService; }