public void DeleteOrder(OrderViewModel vm) { using (var context = new KebapBobEntities()) { var thisorder = context.Order.FirstOrDefault(x => x.Id == vm.Id); if (thisorder == null) { throw new Exception("Record could not found!"); } else { thisorder.Id = vm.Id; thisorder.TrackingNumber = vm.TrackingNumber; thisorder.Address = new Address { Id = vm.AddressId, StreetAddress = vm.StreetName, City = vm.City, State = vm.State, ZipCode = vm.ZipCode, RecipientName = vm.RecipientName }; context.Order.Attach(thisorder); context.Order.Remove(thisorder); context.SaveChanges(); } } }
public void CreateOrder(OrderViewModel vm) { using (var context = new KebapBobEntities()) { var newOrder = new OrderItems { Order = new Order { TrackingNumber = Guid.NewGuid().ToString(), Address = new Address { StreetAddress = vm.StreetName, City = vm.City, State = vm.State, ZipCode = vm.ZipCode, RecipientName = vm.RecipientName }, UserID = vm.UserId } }; context.OrderItems.Add(newOrder); context.SaveChanges(); } }
public List <OrderViewModel> GetOrders(int userId) { using (var context = new KebapBobEntities()) { return(context.Order.Where(x => x.UserID == userId).Select(x => new OrderViewModel { Id = x.Id, RecipientName = x.Address.RecipientName, StreetName = x.Address.StreetAddress, City = x.Address.City, State = x.Address.State, ZipCode = x.Address.ZipCode, TrackingNumber = x.TrackingNumber, OrderItems = x.OrderItems.Select(y => new OrderItemViewModel { Quantity = y.Quantity, Product = new ProductViewModel { Id = y.Product.Id, ItemName = y.Product.Name } }) }).ToList()); } }
public OrderItems AddToOrderCard(OrderItemViewModel vm) { using (var context = new KebapBobEntities()) { return(context.OrderItems.Select(x => new OrderItemViewModel { x.Quantity = vm.Quantity, }));
public List <ProductViewModel> ReturnProductName(int userId) { using (var context = new KebapBobEntities()) { return(context.Product .Where(s => s.UserID == userId) .Select(x => new ProductViewModel { ItemName = x.Name, }).ToList()); } }
public List <ProductViewModel> GetProducts(int userId) { using (var context = new KebapBobEntities()) { return(context.Product .Where(z => z.UserID == userId).Select(x => new ProductViewModel { Id = x.Id, ItemName = x.Name, itemDescription = x.Description }).ToList()); } }
public void CreateProduct(ProductViewModel vm) { using (var context = new KebapBobEntities()) { var newProduct = new Product { Name = vm.ItemName, Description = vm.itemDescription, UserID = vm.UserId }; context.Product.Add(newProduct); context.SaveChanges(); } }
public void UpdateProduct(ProductViewModel vm) { using (var context = new KebapBobEntities()) { var product = context.Product.FirstOrDefault(x => x.Id == vm.Id); if (product == null) { throw new Exception("Product couldn't found"); } product.Name = vm.ItemName; product.Description = vm.itemDescription; context.SaveChanges(); } }
public void UpdateOrder(OrderViewModel vvm) { using (var context = new KebapBobEntities()) { var thisorder = context.Order .Include(d => d.Address) .FirstOrDefault(x => x.Id == vvm.Id); if (thisorder == null) { throw new Exception("Record could not found!"); } thisorder.Address.RecipientName = vvm.RecipientName; thisorder.Address.StreetAddress = vvm.StreetName; thisorder.Address.City = vvm.City; thisorder.Address.State = vvm.State; thisorder.Address.ZipCode = vvm.ZipCode; context.SaveChanges(); } }
public void Register(UserViewModel user) { using (var context = new KebapBobEntities()) { var existingUser = context.User.FirstOrDefault(x => x.UserName == user.UserName); if (existingUser != default(User)) // null { throw new ArgumentException("User already exists!"); } var newUser = new User { UserName = user.UserName, FirstName = user.FirstName, LastName = user.LastName, Password = user.Password }; context.User.Add(newUser); context.SaveChanges(); } }
/// <summary> /// Public Constructor,initializes privately declared local variables. /// </summary> /// <param name="context"></param> public GenericRepository(KebapBobEntities context) { this.Context = context; this.DbSet = context.Set <TEntity>(); }
public UnitOfWork() { _context = new KebapBobEntities(); }