public async Task <ActionResult> Create(RestaurantCreate note) { if (!ModelState.IsValid) { ViewBag.AreaId = await GetAreaAsync(); ViewBag.MenuId = await GetMenuAsync(); return(View(note)); } var service = CreateRestaurantService(); if (await service.CreateRestaurantAsync(note)) { TempData["SaveResult"] = "Restaurant created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Restaurant could not be created."); ViewBag.AreaId = await GetAreaAsync(); ViewBag.MenuId = await GetMenuAsync(); return(View(note)); }
public bool CreateRestaurant(RestaurantCreate model) { var entity = new Restaurant() { Name = model.Name, Phone = model.Phone, Email = model.Email, Address = model.Address, OpeningTime = model.OpeningTime, ClosingTime = model.ClosingTime, AreaId = model.AreaId, // Review = model.Review, Latitude = model.Latitude, Longitude = model.Longitude // MenuId = model.MenuId //Menu = model.Menu }; using (var ctx = new ApplicationDbContext()) { ctx.Restaurants.Add(entity); return(ctx.SaveChanges() == 1); } }
public async Task <bool> CreateRestaurantAsync(RestaurantCreate model) { var entity = new Restaurant() { // OwnerID = _userId, Name = model.Name, Phone = model.Phone, Email = model.Email, Address = model.Address, OpeningTime = model.OpeningTime, ClosingTime = model.ClosingTime, AreaId = model.AreaId, // Review=model.Review, Latitude = model.Latitude, Longitude = model.Longitude //MenuId=model.MenuId }; using (var ctx = new ApplicationDbContext()) { ctx.Restaurants.Add(entity); return(await ctx.SaveChangesAsync() == 1); } }
public IHttpActionResult Post(RestaurantCreate restaurant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateRestaurantService(); if (!service.CreateRestaurant(restaurant)) { return(InternalServerError()); } return(Ok()); }
public bool CreateRestaurant(RestaurantCreate model) { var entity = new Restaurant() { OwnerId = _userId, Name = model.Name, Address = model.Address, Description = model.Description, ContactNumber = model.ContactNumber, ContactEmail = model.ContactEmail, Rating = model.Rating, RestaurantId = model.RestaurantId }; using (var ctx = new ApplicationDbContext()) { ctx.Restaurants.Add(entity); return(ctx.SaveChanges() == 1); } }