예제 #1
0
        public async Task <IHttpActionResult> AddNewOrder(NewOrderViewModel order)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(new ResponseModel <string>(ResponseStatus.BadRequest, null, "Invalid order data.")));
            }
            var user = GetUserInformationFromToken();

            if (user == null || string.IsNullOrEmpty(user.UserId))
            {
                return(BadRequest("Invalid User."));
            }
            var zone = await _locationService.GetZoneFromAddress(order.Lat, order.Lon, order.Address);

            if (string.IsNullOrWhiteSpace(zone))
            {
                return(Ok(new ResponseModel <string>(ResponseStatus.BadRequest, "Sorry, we are not available in this area.", "Sorry, we are not available in this area.")));
            }
            order.Zone = zone;
            var response = await _orderBusiness.AddNewOrder(order, user);

            if (!response)
            {
                return(Ok(new ResponseModel <string>(ResponseStatus.BadRequest, null, "Order was not processed successfully.")));
            }
            return(Ok(new ResponseModel <string>(ResponseStatus.Ok, null, "Order placed successfully.")));
        }