コード例 #1
0
        public async Task <ActionResult> Create([FromBody] SalesOrder salesOrder)
        {
            if (ModelState.IsValid)
            {
                if (salesOrder == null)
                {
                    return(BadRequest());
                }

                var repository = new SalesOrdersRepository(_context);
                try
                {
                    await repository.Insert(salesOrder);

                    repository.Save();

                    return(NoContent());
                }
                catch (Exception e)
                {
                    return(BadRequest(new
                    {
                        message = e.Message.Replace('{', '(').Replace('}', ')')
                    }));
                }
            }
            return(BadRequest(new
            {
                message = "ModelState is not valid"
            }));
        }
コード例 #2
0
        public async Task <ActionResult> Delete(int id)
        {
            var        repository = new SalesOrdersRepository(_context);
            SalesOrder salesOrder = await repository.GetById(id);

            if (salesOrder == null)
            {
                return(NotFound());
            }

            try
            {
                repository.Delete(salesOrder);
                repository.Save();

                return(NoContent());
            }
            catch (Exception e)
            {
                return(BadRequest(new
                {
                    message = e.Message.Replace('{', '(').Replace('}', ')')
                }));
            }
        }