public void Delete(int id) { MenuItem itemToDelete = context.MenuItems.FirstOrDefault(d => d.Id == id); context.MenuItems.Remove(itemToDelete); context.SaveChanges(); }
public bool AddServiceOrderDetail(OrderServiceDetail orderServiceDetail) { OrderServiceDetail s = db.OrderServiceDetails.Where(x => x.OrderId == orderServiceDetail.OrderId && x.ServiceId.Equals((orderServiceDetail.ServiceId))).FirstOrDefault(); if (s != null) { s.Quantity = s.Quantity + 1; if (UpdateServiceOrderDetail(s)) { return(true); } return(false); } else { try { db.OrderServiceDetails.Add(orderServiceDetail); db.SaveChanges(); return(true); } catch (Exception e) { return(false); throw; } } }
public User CreateUser(string name, string username, string password, List <Role> roles) { User user = new User() { Name = name, Username = username, Password = password }; context.Users.Add(user); List <UserRole> userRoles = roles.Select(r => new UserRole() { User = user, UserId = user.Id, RoleId = r.Id, Role = r }).ToList(); foreach (UserRole userRole in userRoles) { user.Roles.Add(userRole); } context.SaveChanges(); return(user); }
public void SetStatusOff(int id) { var invoiceDetails = dbContext.InvoiceDetails.First(item => item.id == id); invoiceDetails.status = false; dbContext.SaveChanges(); }
public ActionResult Create(Product product, string Category, HttpPostedFileBase ImageFile) { if (ImageFile == null) { mImage mImage = new mImage() { Path = $"~/Images/default.jpg", Name = "default" }; product.Image = mImage; } else { product.Image = AddImage(ImageFile); } if (ModelState.IsValid) { Category cat = DbContext.Category.Find(Int32.Parse(Category)); product.Category = cat; DbContext.Product.Add(product); DbContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public void Seed() { if (false == _dbContext.Database.CanConnect()) { return; } var pendingMigrations = _dbContext.Database.GetPendingMigrations(); if (pendingMigrations != null && pendingMigrations.Any()) { _dbContext.Database.Migrate(); } if (false == _dbContext.Roles.Any()) { var roles = GetRoles(); _dbContext.Roles.AddRange(roles); _dbContext.SaveChanges(); } if (false == _dbContext.Restaurants.Any()) { var restaurants = GetRestaurants(); _dbContext.Restaurants.AddRange(restaurants); _dbContext.SaveChanges(); } }
public void Seed() { if (_dbContext.Database.CanConnect()) { /* * var pendingMigrations = _dbContext.Database.GetPendingMigrations(); * if (pendingMigrations != null && pendingMigrations.Any()) * { * _dbContext.Database.Migrate(); * } */ if (!_dbContext.Roles.Any()) { var roles = GetRoles(); _dbContext.Roles.AddRange(roles); _dbContext.SaveChanges(); } if (!_dbContext.Restaurants.Any()) { var restaurants = GetRestaurants(); _dbContext.Restaurants.AddRange(restaurants); _dbContext.SaveChanges(); } } }
public void Delete(int id) { Review review = db.Resviews.Find(id); db.Resviews.Remove(review); db.SaveChanges(); }
public void Seed() { if (_dbContext.Database.CanConnect()) { var pendingMigrations = _dbContext.Database.GetPendingMigrations(); if (pendingMigrations != null && pendingMigrations.Any()) { _dbContext.Database.Migrate(); } if (!_dbContext.Roles.Any()) { var roles = GetRoles(); _dbContext.Roles.AddRange(roles); _dbContext.SaveChanges(); } if (!_dbContext.Restaurants.Any()) { var restaurants = GetRestaurants(); _dbContext.Restaurants.AddRange(restaurants); _dbContext.SaveChanges(); } var user = _dbContext.Users.FirstOrDefault(x => x.Email == "*****@*****.**"); if (user == null) { CreateAdmin(); } } }
public async Task <Guid> Handle(Command request, CancellationToken cancellationToken) { using (var transaction = _context.Database.BeginTransaction()) { var restaurant = new RestaurantModel { Id = Guid.NewGuid(), CityId = request.CityId, Name = request.Name, Notes = request.Notes, ParkingLot = request.ParkingLot, Tried = request.Tried, Yelp = request.Yelp }; _context.Restaurants.Add(restaurant); _context.SaveChanges(); if (request.CuisineIds?.Any() ?? false) { var restaurantCuisines = request.CuisineIds.Select(x => new RestaurantCuisineModel { CuisineId = x, RestaurantId = restaurant.Id }); _context.RestaurantCuisines.AddRange(restaurantCuisines); _context.SaveChanges(); } transaction.Commit(); return(restaurant.Id); } }
public bool AddMealDrinkOrderDetail(OrderMealDrinkDetail orderMealDrinkDetail) { OrderMealDrinkDetail m = db.OrderMealDrinkDetails.Where(x => x.OrderId == orderMealDrinkDetail.OrderId && x.MealDrinkId.Equals(orderMealDrinkDetail.MealDrinkId)).FirstOrDefault(); if (m != null) { m.Quantity += orderMealDrinkDetail.Quantity; if (UpdateOrderDetail(m)) { return(true); } else { return(false); } } else { try { db.OrderMealDrinkDetails.Add(orderMealDrinkDetail); db.SaveChanges(); return(true); } catch (Exception e) { return(false); throw; } } }
public void Seed() { if (_dbContext.Database.CanConnect()) // sprawdza czy mozna połaczyc sie z baza danych. { var pendingMigrations = _dbContext.Database.GetPendingMigrations(); if (pendingMigrations != null && pendingMigrations.Any()) // sprawdza czy są nowe migracje { _dbContext.Database.Migrate(); } if (!_dbContext.Roles.Any()) { var roles = GetRoles(); _dbContext.Roles.AddRange(roles); _dbContext.SaveChanges(); } if (!_dbContext.Restaurants.Any()) // SPRawdza czy cos jest w tabeli. { var restaurants = GetRestaurant(); _dbContext.Restaurants.AddRange(restaurants); _dbContext.SaveChanges(); } } }
public void Delete(int id) { Restaurant restaurant = db.Restaurants.Find(id); db.Restaurants.Remove(restaurant); db.SaveChanges(); }
public void payment(int tableId) { CounterModel model = new CounterModel(); var currentTable = entity.Tables.SingleOrDefault(table => table.Number == tableId); var currentInvoice = entity.Invoices.SingleOrDefault(invoice => invoice.Number == tableId && !invoice.Status); if (currentInvoice == null) { model.TableList = entity.Tables.ToList(); RedirectToAction("Index", model); } if (currentInvoice != null) { currentTable.Status = false; var invoiceDetail = entity.InvoiceDetails.Where(i => i.ID_Invoice == currentInvoice.ID_Invoice).ToList(); foreach (var element in invoiceDetail) { var item = element; entity.Entry(item).State = System.Data.Entity.EntityState.Deleted; } entity.Entry(currentInvoice).State = System.Data.Entity.EntityState.Deleted; entity.SaveChanges(); } }
public void Update(int id, UpdateRestaurantDto dto) { var restaurant = _dbContext .Restaurants .FirstOrDefault(r => r.Id == id); if (restaurant is null) { throw new NotFoundException("Restaurant not found"); } var authorizationResult = _authorizationService.AuthorizeAsync(_userContextService.User, restaurant, new ResourceOperationRequirement(ResourceOperation.Update)).Result; if (!authorizationResult.Succeeded) { throw new ForbidException(); } restaurant.Name = dto.Name; restaurant.HasDelivery = dto.HasDelivery; restaurant.Description = dto.Description; _dbContext.SaveChanges(); }
public int Create(CreateRestaurantDto dto) { var restaurant = _mapper.Map <Restaurant>(dto); _dbContext.Restaurants.Add(restaurant); _dbContext.SaveChanges(); return(restaurant.Id); }
public bool DeleteService(string serviceId) { db.Services.Remove(GetServiceById(serviceId)); db.SaveChanges(); return(true); db.SaveChanges(); }
public Restaurant Create(RestaurantPostModel restaurant) { Restaurant restaurantToAdd = RestaurantPostModel.ToRestaurant(restaurant); restaurantToAdd.IsActive = true; context.Restaurants.Add(restaurantToAdd); context.SaveChanges(); return(restaurantToAdd); }
public void CloseSession(int id) { var session = _context.Session.Where(x => x.SessionId == id).FirstOrDefault(); var table = _context.Table.Where(x => x.TableId == session.TableId).FirstOrDefault(); table.IsAvailable = true; _context.Table.Update(table); _context.SaveChanges(); }
public ActionResult Delete(int id) { Restaurant restaurant = _db.Restaurants.Find(id); _db.Restaurants.Remove(restaurant); _db.SaveChanges(); return(RedirectToAction("Index")); }
public int Create(int restaurantId, CreateDishDto dto) { var restaurant = GetRestaurantById(restaurantId); var dishEntity = _mapper.Map <Dish>(dto); dishEntity.RestaurantId = restaurantId; _dbContext.Dishes.Add(dishEntity); _dbContext.SaveChanges(); return(dishEntity.Id); }
public ActionResult Edit([Bind(Include = "Id,ReviewerName, Rating,Comment,DateRated, Restaurant_RestaurantId, ReviewerId ")] RestaurantReview restaurantReview) { if (ModelState.IsValid) { db.Entry(restaurantReview).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { restId = restaurantReview.Restaurant_RestaurantId })); } return(View(restaurantReview)); }
public IActionResult Index(Reservation reservation) { //add ind. reservation to the database _context.Reservations.Add(reservation); //Saving the entry _context.SaveChanges(); //Redirect to details action return(RedirectToAction("Details")); }
[ValidateAntiForgeryToken] //"annotation that allows the server to match up with the AntiForgeryToken that we have set in the Create form." public ActionResult Create(Restaurant restaurant) //Like our previous create method, except this one takes in a Restaurant item as a parameter. That restaurant item "is the model that the view is going to give the controller once POST is called." { if (ModelState.IsValid) { //Inside the if statement we see the _db field called, and the Restaurants property accessed. From there the .Add() method is called where we are adding the restaurant parameter to the Restaurants table." _db.Restaurants.Add(restaurant); //adds restaurant item to _db _db.SaveChanges(); //"...we call the _db.SaveChanges() method, which takes our modified snapshot and saves those changes to the actuall SQL database. SaveChanges() also returns an int with the count of how many rows were modified. We are not using this right now but it would be good to know for the future." return(RedirectToAction("Index")); } return(View(restaurant)); }
[ValidateAntiForgeryToken]//allow server to match up with the antiforgeryToken public ActionResult Create(Restaurant restaurant) { if (ModelState.IsValid)//check the model given to the method { _db.Restaurants.Add(restaurant); _db.SaveChanges(); return RedirectToAction("Index"); } return View(restaurant); }
public ActionResult Create(Restaurant restaurant) { if (ModelState.IsValid) { _db.Restaurants.Add(restaurant); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(restaurant)); }
public int Create(CreateRestaurantDto dto) { var restaurant = _mapper.Map <Restaurant>(dto); restaurant.CreatedById = _userContextService.GetUserId; _dbContext.Restaurants.Add(restaurant); _dbContext.SaveChanges(); return(restaurant.Id); }
[HttpPost, ValidateAntiForgeryToken] //Just to show this is ONLY a post because there is another create method. ValidateAntiForegeryToken-- see in the view public ActionResult Create(Restaurant restaurant) { if (ModelState.IsValid) { _db.Restaurants.Add(restaurant); _db.SaveChanges(); return(RedirectToAction("Index"));//Return to home page of Restaurant } return(View(restaurant));//give model back to the view -- aka puts everything back in the form that you sent autopopulated. This would be like if you have one error and everything is still saved for you. }
public ActionResult Create([Bind(Include = "WarehouseTypeId,WarehouseName,Description")] WarehouseType warehouseType) { if (ModelState.IsValid) { db.WarehouseTypes.Add(warehouseType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(warehouseType)); }
public ActionResult Create(Restaurant restaurant) { if (ModelState.IsValid) { _db.Restaurants.Add(restaurant); // Add the newly created restaurant to the database _db.SaveChanges(); // Save the changes to the database return(RedirectToAction("index")); // Then redirect to the index } return(View(restaurant)); // This returns the model that users have already filled out and simply returns it back to the view and populates for us, so you wont lose anything you've filled out }