예제 #1
0
        public ActionResult <CreateRestaurant> CreateRestaurant([FromBody] CreateRestaurant model)
        {
            try
            {
                var restaurantType = _repository.GetRestaurantTypeByID(model.RestaurantTypeID);
                if (restaurantType == null)
                {
                    return(BadRequest("Restaurant type could not be find"));
                }

                var cuisineType = _repository.GetCuisineTypeById(model.CuisineTypeID);
                if (cuisineType == null)
                {
                    return(BadRequest("Cuisine type could not be find"));
                }

                IMapper mapper     = EDeliveryProfile.CreateRestaurant();
                var     restaurant = mapper.Map <Restaurant>(model);

                _repository.CreateNewRestaurant(restaurant);
                return(new ObjectResult(new { message = "success", statusCode = HttpStatusCode.OK, response = "Created restaurant" }));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to create new restaurant:{ex}");
                return(BadRequest("Failed to create new restaurant: "));
            }
        }
        public IHttpActionResult Create(CreateRestaurant model)
        {
            IHttpActionResult httpActionResult;
            ErrorsModel       errors = new ErrorsModel();

            if (string.IsNullOrEmpty(model.name))
            {
                errors.Add("Tên nhà hàng là trường bắt buộc");
            }

            if (errors.Errors.Count == 0)
            {
                Restaurants t = new Restaurants();
                t.id      = model.id;
                t.name    = model.name;
                t.address = model.address;
                t.type    = model.type;

                t = _db.Restaurants.Add(t);

                this._db.SaveChanges();

                RestaurantModel viewModel = new RestaurantModel(t);

                httpActionResult = Ok(viewModel);
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors);
            }

            return(httpActionResult);
        }
예제 #3
0
        public void AddNewRestaurantTest()
        {
            // TODO: add unit test for the method 'AddNewRestaurant'
            CreateRestaurant value = null; // TODO: replace null with proper value
            var response           = instance.AddNewRestaurant(value);

            Assert.IsInstanceOf <WithAccessTokenContract1RestaurantContract> (response, "response is WithAccessTokenContract1RestaurantContract");
        }
예제 #4
0
        public IActionResult Create(CreateRestaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                Restaurant _restaurant = new Restaurant()
                {
                    Name   = restaurant.Name,
                    Cousin = restaurant.Cousin
                };
                _restaurant = _restaurantData.AddRestaurant(_restaurant);

                return(RedirectToAction("Detail", new { Id = _restaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
예제 #5
0
        public async Task <IActionResult> Post([FromBody] CreateRestaurant command)
        {
            await _busClient.PublishAsync(command);

            return(Accepted());
        }
 public void Init()
 {
     instance = new CreateRestaurant();
 }
예제 #7
0
 public async Task Create(CreateRestaurant input)
 {
     Restaurant output = Mapper.Map <CreateRestaurant, Restaurant>(input);
     await _restaurantManager.Create(output);
 }