public int Save(DishAvailability dishAvail)
        {
            DishAvailability dbDishAvail;

            if (dishAvail.Id == 0)
            {
                var newDish = _context.DishesAvail.Add(dishAvail);
                _context.SaveChanges();
                dbDishAvail = newDish.Entity;
            }
            else
            {
                dbDishAvail = _context.DishesAvail.FirstOrDefault(da => da.Id == dishAvail.Id);
                if (dbDishAvail != null)
                {
                    dbDishAvail.StartDate     = dishAvail.StartDate;
                    dbDishAvail.EndDate       = dishAvail.EndDate;
                    dbDishAvail.OriginalPrice = dishAvail.OriginalPrice;
                    dbDishAvail.DiscountPrice = dishAvail.DiscountPrice;
                    dbDishAvail.Quantity      = dishAvail.Quantity;
                    dbDishAvail.QuantityTotal = dishAvail.QuantityTotal;
                }
            }

            _context.SaveChanges();

            return(dbDishAvail.Id);
        }
 public void AddProduct(Product product)
 {
     if (product == null)
     {
         throw new ArgumentNullException(nameof(product));
     }
     _dataContext.Products.Add(product);
     _dataContext.SaveChanges();
 }
Esempio n. 3
0
        public void Add(Meals_Create model)
        {
            var meal = new Meal(model.userid, model.datetime);

            List <MealDish> dishList = new List <MealDish>();
            var             dish     = _context.Dishes.Find(model.dishid);

            dishList.Add(new MealDish(meal, dish));

            meal.Dishes = dishList;

            _context.Add(meal);
            _context.SaveChanges();
        }
Esempio n. 4
0
        public void Add(WorkoutCreateVM model)
        {
            var workout = new Workout(model.userid, model.starttime, model.endtime);

            List <WorkoutExcercise> exList = new List <WorkoutExcercise>();
            var exercise = _context.Excercises.Find(model.exerciseid);

            exList.Add(new WorkoutExcercise(workout, exercise));

            workout.Excercises = exList;

            _context.Add(workout);
            _context.SaveChanges();
        }
Esempio n. 5
0
        public int Create(Order order)
        {
            _context.AttachRange(order.Items.Select(l => l.DishAvail));
            var newOrder = _context.Orders.Add(order);

            _context.SaveChanges();

            foreach (var orderItem in order.Items)
            {
                orderItem.DishAvail.Quantity -= orderItem.Quantity;
                _dishAvailabilityRepository.Update(orderItem.DishAvail);
            }

            return(newOrder.Entity.Id);
        }
Esempio n. 6
0
        public ResponseVM Logout(RequestVM request)
        {
            ApplicationUser user = _userContext.Users.Find(request.User.Id);

            if (user == null)
            {
                return(new ResponseVM(false));
            }

            user.Token      = "";
            user.TimeToLive = 0;
            _userContext.SaveChanges();

            return(new ResponseVM(true));
        }
Esempio n. 7
0
        public async Task <IActionResult> PostImage(IFormFile file, string caption, bool isDefault, int pId)
        {
            if (file == null || file.Length == 0)
            {
                return(Content("File not selected"));
            }

            string path_root     = henv.WebRootPath;
            string path_to_Image = path_root + "\\Upload\\" + file.FileName;

            using (var stream = new FileStream(path_to_Image, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
            pImage im = new pImage();

            //im.ImageID = ivm.ImageID;
            im.FilePathOrLink = path_to_Image;
            im.ShortDetails   = file.FileName;
            im.Caption        = caption;
            //im.IsDefault = isDefault;
            //im.ProductID = pId;
            _context.Images.Add(im);
            _context.SaveChanges();

            return(Ok("Upload image successful"));
        }
Esempio n. 8
0
 public void Save(ContactUs contactUs)
 {
     if (contactUs.Id == 0)
     {
         context.ContactUs.Add(contactUs);
     }
     else
     {
         ContactUs regDb = context.ContactUs.FirstOrDefault(r => r.Id == contactUs.Id);
         if (regDb != null)
         {
             regDb.Name    = contactUs.Name;
             regDb.Email   = contactUs.Email;
             regDb.Message = contactUs.Message;
         }
     }
     context.SaveChanges();
 }
        public int Create(OrderItem orderItem)
        {
            var newOrder = _context.OrderItems.Add(orderItem);

            _context.SaveChanges();
            orderItem = newOrder.Entity;

            return(orderItem.Id);
        }
Esempio n. 10
0
        public ResponseVM CreateNew(RegisterRequest request)
        {
            if (_userContext.Users.Any(u => u.Email == request.Email))
            {
                return(new ResponseVM(false));
            }

            var passwordhash = CryptoUtils.GetMD5Hash(request.Password);

            var newUser = new ApplicationUser(request.Email, passwordhash);

            var user = _userContext.Add(newUser).Entity;

            _userContext.SaveChanges();

            user = CreateUserToken(user);

            return(new ResponseVM(true, UserDTO.Create(user)));
        }
        public int Save(DishType dishType)
        {
            DishType dbDishType;

            if (dishType.Id == 0)
            {
                var newDT = context.DishTypes.Add(dishType);
                context.SaveChanges();
                dbDishType = newDT.Entity;
            }
            else
            {
                dbDishType = context.DishTypes.FirstOrDefault(r => r.Id == dishType.Id);
                if (dbDishType != null)
                {
                    dbDishType.TypeName = dishType.TypeName;
                }
            }

            context.SaveChanges();
            return(dbDishType.Id);
        }
Esempio n. 12
0
        public Partner Save(Partner partner)
        {
            Partner dbPartner = context.Partners.FirstOrDefault(r => r.Id == partner.Id);

            if (dbPartner == null)
            {
                var newPartner = context.Partners.Add(partner);
                context.SaveChanges();
                dbPartner = newPartner.Entity;
            }
            else
            {
                dbPartner.Rate       = partner.Rate;
                dbPartner.Address    = partner.Address;
                dbPartner.City       = partner.City;
                dbPartner.PostalCode = partner.PostalCode;
                dbPartner.Latitude   = partner.Latitude;
                dbPartner.Longitude  = partner.Longitude;
                context.SaveChanges();
            }

            return(dbPartner);
        }
        public string Save(Customer customer)
        {
            Customer dbCustomer;

            dbCustomer = context.Customers.FirstOrDefault(c => c.Id == customer.Id);
            if (dbCustomer == null)
            {
                var newCustomer = context.Customers.Add(customer);
                context.SaveChanges();
                dbCustomer = newCustomer.Entity;
            }
            else
            {
                dbCustomer.FirstName  = customer.FirstName;
                dbCustomer.LastName   = customer.LastName;
                dbCustomer.Address    = customer.Address;
                dbCustomer.City       = customer.City;
                dbCustomer.PostalCode = customer.PostalCode;
                context.SaveChanges();
            }

            return(dbCustomer.Id);
        }
        public int Save(Dish dish)
        {
            Dish dbDish;

            if (dish.Id == 0)
            {
                var newDish = context.Dishes.Add(dish);
                context.SaveChanges();
                dbDish = newDish.Entity;
            }
            else
            {
                dbDish = context.Dishes.FirstOrDefault(r => r.Id == dish.Id);
                if (dbDish != null)
                {
                    dbDish.Name        = dish.Name;
                    dbDish.Description = dish.Description;
                    dbDish.Type        = dish.Type;
                }
            }

            context.SaveChanges();
            return(dbDish.Id);
        }
 public void Save()
 {
     _dataContext.SaveChanges();
 }