예제 #1
0
        public IActionResult Create([FromBody]OrderDto orderDto)
        {

            string userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value;
            Guid gORderNumber = Guid.NewGuid();

            string OrderNumber = gORderNumber.ToString();

            //var userId = int.Parse(context.Principal.Identity.Name);
            var user = _userService.GetById(int.Parse(userId));


            try
            {
                Order order = orderDto.ToModel();

                // Audit fields
                order.createdBy = user.Username;
                order.Created = DateTime.Now;
                order.OrderNumber = OrderNumber;

                Order returnedOrder = _orderService.Create(order, user);

                OrderDto r = OrderDto.FromModel(returnedOrder);
                return Ok(r);

            }
            catch (AppException ex)
            {
                //var Message = ex.Message;
                return ErrorResponse(ex.Message);
                //return BadRequest(new  { message = ex.Message });
            }
        }