public ActionResult createRestaurantAccount() { CreateRestaurantModel create = new CreateRestaurantModel(); // create.dropDownListRegion = "West Region"; return(View()); }
public async Task <ActionResult <RestaurantDTO> > Create([FromBody] CreateRestaurantModel crm) { if (!ModelState.IsValid || crm == null) { return(BadRequest(ModelState)); } var restaurant = _restaurantService.Create(crm); return(Ok(await restaurant)); //return CreatedAtRoute("GetRestaurant", new { id = restaurant.Id.ToString() }, restaurant); }
public async Task <IActionResult> Create() { var categories = await _categoryData.GetCategories(); CreateRestaurantModel model = new CreateRestaurantModel(); categories.ForEach(x => { model.CategoryItems.Add(new SelectListItem { Value = x.Id.ToString(), Text = x.CategoryName }); }); return(View(model)); }
public IActionResult Edit(int id, CreateRestaurantModel restaurantModel) { if (ModelState.IsValid) { var restaurant = this.restaurantRepo.Get(id); restaurant.Name = restaurantModel.Name; restaurant.Cuisine = restaurantModel.Cuisine; this.restaurantRepo.Edit(restaurant); return(this.RedirectToAction("Detail", new { id = id })); } return(base.View()); }
public IActionResult Create(CreateRestaurantModel restaurantModel) { if (ModelState.IsValid) { var restaurant = new Restaurant { Name = restaurantModel.Name, Cuisine = restaurantModel.Cuisine }; int id = this.restaurantRepo.Add(restaurant); restaurant.Id = id; return(this.RedirectToAction("Detail", new { id = id })); } return(base.View()); }
public async Task <RestaurantDTO> Create(CreateRestaurantModel crm) { var menu = await _menuService.Create(); var restaurant = new Restaurant() { Email = crm.Email, RestaurantName = crm.RestaurantName, RestaurantType = crm.RestaurantType, Cvr = crm.Cvr, Address = crm.Address, PostalCode = crm.PostalCode, City = crm.City, Country = crm.Country, MenuId = menu.Id }; await _restaurants.InsertOneAsync(restaurant); return(restaurant.ToRestaurantDTO()); }
public SaveResponse AddRestaurant([FromBody] CreateRestaurantModel restaurant) { if (!ValidateRestaurant(restaurant)) { _logger.LogWarning("Invalid restaurant model"); return(new SaveResponse { ErrorMessage = "Unable to add Restaurant: Invalid model." }); } /*if (!User.IsInRole("AddRestaurant")) * { * _logger.LogWarning("Unauthorized access attempt"); * return new SaveResponse { ErrorMessage = "You are not authorized to add restautants" }; * }*/ var service = new RestaurantService(new RestaurantDataAccess()); // assumption: (not shown) all write operations would normally receive user information from the controller return(service.AddRestaurant(restaurant)); }
// assumption: we would valid a creation model as valid // it wouldn't need to go here, this is just an example // it could be on the model, a static extension method, a service call... private bool ValidateRestaurant(CreateRestaurantModel restaurant) { return(restaurant.RestaurantName != null && restaurant.CityId > 0); }