示例#1
0
        public async Task <IActionResult> CreateSupplier(SupplierDto supplierDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (supplierDto.Id != 0)
                {
                    return(BadRequest("The Id should be empty"));
                }

                var createdSupplier = await _supplierService.CreateAsync(supplierDto);

                var integrationEventData = JsonConvert.SerializeObject(new
                {
                    id          = createdSupplier.Id,
                    companyName = createdSupplier.CompanyName
                });
                PublishToMessageQueue("suppliers.add", integrationEventData);

                _logger.LogInformation($"Supplier added, id {createdSupplier.Id}");

                //Fetch the supplier from data source
                return(CreatedAtRoute("GetSupplierById", new { id = createdSupplier.Id }, createdSupplier));
            }
            catch (DbQueryResultNullException e)
            {
                return(NotFound(e.Message));
            }
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("SupplierId,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,HomePage")] Suppliers suppliers)
        {
            if (ModelState.IsValid)
            {
                await _supplierService.CreateAsync(suppliers);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(suppliers));
        }
示例#3
0
        public async Task <IHttpActionResult> CreateCategories([FromBody] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                var result = await _supplierService.CreateAsync(supplier);

                return(Ok(result));
            }

            return(BadRequest());
        }
        public async Task <IActionResult> Create([FromBody] SupplierDTO supplierDto)
        {
            var createdDto = await _supplierService.CreateAsync(supplierDto);

            if (createdDto != null)
            {
                return(CreatedAtAction(nameof(Create), createdDto));
            }

            return(BadRequest());
        }
示例#5
0
        public async Task <ActionResult> Create(SupplierDTO supplier)
        {
            try
            {
                await _supplierService.CreateAsync(supplier);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <ActionResult> Create(SupplierViewModel supplierViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var supplier = Mapper.Map <Supplier>(supplierViewModel);

                    supplier.Status = CommonStatus.Active;
                    await _supplierService.CreateAsync(supplier, true);

                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
            }
            return(View());
        }
示例#7
0
        public async Task <IActionResult> CreateSupplier(SupplierDto supplierDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (supplierDto.Id != 0)
                {
                    return(BadRequest("The Id should be empty"));
                }

                var createdSupplier = await _supplierService.CreateAsync(supplierDto);

                //Fetch the supplier from data source
                return(CreatedAtRoute("GetSupplierById", new { id = createdSupplier.Id }, createdSupplier));
            }
            catch (DbQueryResultNullException e)
            {
                return(NotFound(e.Message));
            }
        }
示例#8
0
        public async Task <IActionResult> PostAsync([FromBody] SupplierForCreationDto value)
        {
            await _supplierService.CreateAsync(value);

            return(Ok());
        }
示例#9
0
 public async Task <object> CreateSupplier([Bind("Name,ContactNo,Email,City,PostalCode,Country,Image")] Supplier supplier)
 {
     return(await _supplierService.CreateAsync(supplier));
 }
 public async Task <IActionResult> Create([FromBody] SupplierDTO supplierDto)
 {
     return(CreatedAtAction(nameof(Create), await _supplierService.CreateAsync(supplierDto)));
 }