Example #1
0
        public static ResponResultViewModel Delete(int id)
        {
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new KitchenContext())
                {
                    Student st = db.Students.Where(x => x.id == id).FirstOrDefault();

                    if (st != null)
                    {
                        result.Entity = st;
                        db.Students.Remove(st);
                        db.SaveChanges();
                    }
                    else
                    {
                        result.Success = false;
                        result.Message = "Students not found";
                    }
                }
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Message = e.Message;
            }
            return(result);
        }
Example #2
0
        public void UpdateQuantity(KitchenContext context, int ingredientId, int amount)
        {
            var ingredient = context.Ingredients.Find(ingredientId);

            ingredient.Quantity = ingredient.Quantity + amount;
            context.SaveChanges();
        }
Example #3
0
 public IEnumerable <Omelette> GetOmelettesCookedToday()
 {
     using (var context = new KitchenContext())
     {
         return(_omeletteReader.GetOmelettesCookedByDay(context, DateTime.Today).ToList());
     }
 }
Example #4
0
        public static StudentViewModel GetStudent(int id)
        {
            StudentViewModel result = new StudentViewModel();

            using (var db = new KitchenContext())
            {
                result = (from c in db.Students
                          where c.id == id
                          select new StudentViewModel
                {
                    id = c.id,
                    firstname = c.firstname,
                    lastname = c.lastname,
                    gender = c.gender,
                    dob = c.dob,
                    pob = c.pob,
                    Active = c.Active
                }).FirstOrDefault();
                if (result == null)
                {
                    result = new StudentViewModel();
                }
            }
            return(result);
        }
Example #5
0
        public static ProductViewModel GetProduct(int id)
        {
            ProductViewModel result = new ProductViewModel();

            using (var db = new KitchenContext())
            {
                result = (from d in db.Products
                          join c in db.Categories on d.categoryid equals c.id
                          where d.id == id
                          select new ProductViewModel
                {
                    id = d.id,
                    initial = d.initial,
                    name = d.name,
                    categoryid = d.categoryid,
                    CategoryName = c.Name,
                    price = d.price,
                    description = d.description,
                    Active = d.Active
                }).FirstOrDefault();
                if (result == null)
                {
                    result = new ProductViewModel();
                }
            }
            return(result);
        }
Example #6
0
        public static ReservationVIewModel GetByTable(int tableid)
        {
            ReservationVIewModel result = new ReservationVIewModel();

            using (var db = new KitchenContext())
            {
                result = (from r in db.Reservations
                          join t in db.Tables on
                          r.tableid equals t.id
                          where r.tableid == tableid
                          select new ReservationVIewModel
                {
                    id = r.id,
                    tableid = r.tableid,
                    tableinit = t.initial,
                    tabledesc = t.Desc,
                    reference = r.reference,
                    Paid = r.Paid,
                    guest = r.guest,
                    Active = r.Active
                }).FirstOrDefault();

                return(result == null ? result = new ReservationVIewModel() : result);
            }
        }
 public void Save(KitchenContext context, Recipe currentOrder)
 {
     context.Omelettes.Add(new Omelette {
         Recipe = currentOrder, DateCooked = DateTime.Today
     });
     context.SaveChanges();
 }
Example #8
0
        public override string[] GetRolesForUser(string Login)
        {
            string[] role = new string[] { };
            using (KitchenContext db = new KitchenContext())
            {
                // Получаем пользователя
                User user = db.Users.FirstOrDefault(u => u.Login == Login);
                if (user != null)
                {
                    // Получаем роль
                    Role userRole = db.Roles.Find(user.RoleId);
                    if (userRole != null)
                    {
                        switch (userRole.Name) // В зависимости от роли, добавляем список ролей
                        {
                        case "Admin":
                            role = new string[] { "Admin", "Moder", "User" };
                            break;

                        case "Moder":
                            role = new string[] { "Moder", "User" };
                            break;

                        case "User":
                            role = new string[] { "User" };
                            break;
                        }
                    }
                }
            }
            return(role);
        }
Example #9
0
        public static ResponResultViewModel Delete(int id)
        {
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new KitchenContext())
                {
                    Product prod = db.Products.Where(x => x.id == id).FirstOrDefault();

                    if (prod != null)
                    {
                        result.Entity = prod;
                        db.Products.Remove(prod);
                        db.SaveChanges();
                    }
                    else
                    {
                        result.Success = false;
                        result.Message = "Products not found";
                    }
                }
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Message = "Category memiliki Product, tidak dapat dihapus";
            }
            return(result);
        }
Example #10
0
        public static List <OrderViewModel> GetByReserv(int id)
        {
            //id=>reseid
            List <OrderViewModel> result = new List <OrderViewModel>();

            using (var db = new KitchenContext())
            {
                result = (from r in db.Reservations
                          join o in db.Orders on
                          r.id equals o.reservid
                          join p in db.Products on
                          o.productid equals p.id
                          where r.id == id
                          select new OrderViewModel
                {
                    id = o.id,
                    reservid = r.id,
                    productid = o.productid,
                    productname = p.name,
                    price = o.price,
                    quantity = o.quantity,
                    status = o.status,
                    Active = o.Active
                }).ToList();
            }
            return(result.Count == 0 ? new List <OrderViewModel>() : result);
        }
Example #11
0
 public IEnumerable <Ingredient> GetAvailableIngredients()
 {
     using (var context = new KitchenContext())
     {
         return(_ingredientReader.GetIngredients(context).Where(x => x.Quantity > 0).ToList());
     }
 }
Example #12
0
 public void TestCategory()
 {
     using (var db = new KitchenContext())
     {
         Trace.WriteLine("--- Starting Category Testing ");
         Category cat = new Category()
         {
             initial    = "MC",
             Name       = "Main Course",
             Active     = true,
             CreateBy   = "Bloobloo",
             CreateDate = DateTime.Now
         };
         db.Categories.Add(cat);
         cat = new Category()
         {
             initial    = "Dr",
             Name       = "Drink",
             Active     = true,
             CreateBy   = "Bloobloo",
             CreateDate = DateTime.Now
         };
         db.Categories.Add(cat);
         db.SaveChanges();
         foreach (var category in db.Categories.ToList())
         {
             Trace.WriteLine(category.Name);
         }
         Trace.WriteLine("--- Ending Category Testing ");
     }
 }
Example #13
0
 public Recipe GetOrder()
 {
     using (var context = new KitchenContext())
     {
         CurrentOrder = _recipeReader.GetRecipes(context).OrderBy(x => Guid.NewGuid()).Take(1).First();
         return(CurrentOrder);
     }
 }
Example #14
0
 public void Open()
 {
     using (var context = new KitchenContext())
     {
         AvailableRecipes     = _recipeReader.GetRecipes(context).ToList();
         AvailableIngredients = _ingredientReader.GetIngredients(context).Where(x => x.Quantity > 0).ToList();
     }
 }
Example #15
0
        public static ResponResultViewModel Update(TableViewModel entity)
        {
            //Untuk create dan edit
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new KitchenContext())
                {
                    //Create
                    if (entity.id == 0)
                    {
                        Table table = new Table();
                        table.initial = entity.initial;
                        table.Seat    = entity.Seat;
                        table.Desc    = entity.Desc;
                        table.Active  = entity.Active;

                        table.CreateBy   = "Bloblo";
                        table.CreateDate = DateTime.Now;
                        db.Tables.Add(table);
                        db.SaveChanges();

                        result.Entity = table;
                    }
                    //Edit
                    else
                    {
                        Table table = db.Tables.Where(o => o.id == entity.id).FirstOrDefault();
                        if (table != null)
                        {
                            table.initial = entity.initial;
                            table.Seat    = entity.Seat;
                            table.Desc    = entity.Desc;
                            table.Active  = entity.Active;

                            table.ModifyBy   = "Booboo";
                            table.ModifyDate = DateTime.Now;


                            db.SaveChanges();
                            result.Entity = entity;
                        }
                        else
                        {
                            result.Success = false;
                            result.Message = "table not Found!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Example #16
0
        public static ResponResultViewModel Update(CategoryViewModel entity)
        {
            //Untuk create dan edit
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new KitchenContext())
                {
                    //Create
                    if (entity.id == 0)
                    {
                        Category category = new Category();
                        category.initial = entity.initial;
                        category.Name    = entity.Name;
                        category.Active  = entity.Active;

                        category.CreateBy   = "Bloblo";
                        category.CreateDate = DateTime.Now;
                        db.Categories.Add(category);
                        db.SaveChanges();

                        result.Entity = category;
                    }
                    //Edit
                    else
                    {
                        Category category = db.Categories.Where(o => o.id == entity.id).FirstOrDefault();
                        if (category != null)
                        {
                            category.initial = entity.initial;
                            category.Name    = entity.Name;
                            category.Active  = entity.Active;

                            category.ModifyBy   = "Booboo";
                            category.ModifyDate = DateTime.Now;

                            db.SaveChanges();

                            result.Entity = entity;
                        }
                        else
                        {
                            result.Success = false;
                            result.Message = "Category not Found!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Example #17
0
        public override void CreateRole(string roleName)
        {
            Role newRole = new Role()
            {
                Name = roleName
            };
            KitchenContext db = new KitchenContext();

            db.Roles.Add(newRole);
            db.SaveChanges();
        }
Example #18
0
 public void GetDelivery()
 {
     using (var context = new KitchenContext())
     {
         var allIngredientsIds = _ingredientReader.GetIngredients(context).Select(x => x.IngredientId).ToList();
         foreach (var id in allIngredientsIds)
         {
             _ingredientWriter.UpdateQuantity(context, id, new Random().Next(1, 10));
         }
     }
 }
Example #19
0
 public void TestTables()
 {
     using (var db = new KitchenContext())
     {
         Trace.WriteLine("--- Starting Table Testing ");
         foreach (var tables in db.Tables.ToList())
         {
             Trace.WriteLine(tables.initial);
         }
         Trace.WriteLine("--- Ending Table Testing ");
     }
 }
        public KitchenControllerTest()
        {
            dbContextOptions = new DbContextOptionsBuilder <KitchenContext>()
                               .UseInMemoryDatabase(databaseName: "in-memory")
                               .Options;

            using (var dbContext = new KitchenContext(dbContextOptions))
            {
                dbContext.AddRange(GetFakeData());
                dbContext.SaveChanges();
            }
            logger = new Mock <ILogger <KitchenController> >().Object;
        }
Example #21
0
        public static ResponResultViewModel WorkFlow(OrderViewModel entity)
        {
            ResponResultViewModel res = new ResponResultViewModel();

            try
            {
                using (var db = new KitchenContext())
                {
                    if (entity.id == 0)
                    {
                        Order ord = new Order();
                        ord.reservid  = entity.reservid;
                        ord.productid = entity.productid;
                        ord.quantity  = entity.quantity;
                        ord.price     = entity.price;
                        ord.status    = entity.status + 1;

                        ord.Active     = true;
                        ord.CreateBy   = "OrderBlu";
                        ord.CreateDate = DateTime.Now;

                        db.Orders.Add(ord);
                        db.SaveChanges();

                        res.Entity = ord;
                    }
                    else
                    {
                        Order order = db.Orders.Where(o => o.id == entity.id).FirstOrDefault();
                        if (order == null)
                        {
                            res.Success = false;
                            res.Message = "Ord Not FOund";
                        }
                        else
                        {
                            order.status = order.status + 1;
                            db.SaveChanges();
                            res.Entity = entity;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                res.Success = false;
                res.Message = e.Message;
            }
            return(res);
        }
Example #22
0
        public Recipe CookCurrentOrder()
        {
            using (var context = new KitchenContext())
            {
                _omeletteWriter.Save(context, CurrentOrder);

                foreach (var ingredient in CurrentOrder.Ingredients)
                {
                    _ingredientWriter.UpdateQuantity(context, ingredient.IngredientId, -1);
                }
            }

            return(CurrentOrder);
        }
Example #23
0
        public Dictionary <string, int> GetOmelettesCooked()
        {
            using (var context = new KitchenContext())
            {
                var dictionary = new Dictionary <string, int>();
                var omelettes  = _omeletteReader.GetAllOmelettesCooked(context);

                foreach (var omelette in omelettes)
                {
                    dictionary[omelette.Recipe.Name] = dictionary.ContainsKey(omelette.Recipe.Name) ? dictionary[omelette.Recipe.Name] + 1 : 1;
                }

                return(dictionary);
            }
        }
Example #24
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = null;
                using (KitchenContext db = new KitchenContext())
                {
                    user = db.Users.FirstOrDefault(u => u.Login == model.Login);
                }
                if (user == null)
                {
                    // создаем нового пользователя
                    using (KitchenContext db = new KitchenContext())
                    {
                        user = new User {
                            Login = model.Login, Password = model.Password, DateOfRegistration = DateTime.Now, Role = db.Roles.Where(i => i.Name == "User").FirstOrDefault(), Email = model.Email
                        };
                        db.Users.Add(user);
                        var userProfile = new UserProfile()
                        {
                            DateOfBirth = DateTime.Now,
                            Gender      = null,
                            Name        = "",
                            Surname     = "",
                            PhotoUrl    = "",
                            User        = user
                        };
                        db.UserProfilies.Add(userProfile);
                        db.SaveChanges();

                        user = db.Users.Where(u => u.Login == model.Login && u.Password == model.Password).FirstOrDefault();
                    }
                    // если пользователь удачно добавлен в бд
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Login, true);
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }

            return(View(model));
        }
Example #25
0
        public static List <CategoryViewModel> All()
        {
            List <CategoryViewModel> result = new List <CategoryViewModel>();

            using (var db = new KitchenContext())
            {
                result = (from c in db.Categories
                          select new CategoryViewModel
                {
                    id = c.id,
                    initial = c.initial,
                    Name = c.Name,
                    Active = c.Active
                }).ToList();
            }
            return(result);
        }
Example #26
0
        public static OrderViewModel GetByProduct(int id)
        {
            //id = prodid
            OrderViewModel result = new OrderViewModel();

            using (var db = new KitchenContext())
            {
                result = (from p in db.Products
                          where p.id == id
                          select new OrderViewModel
                {
                    productid = p.id,
                    productname = p.name,
                    price = p.price
                }).FirstOrDefault();
            }
            return(result == null ? new OrderViewModel() : result);
        }
Example #27
0
        public static List <TableViewModel> All()
        {
            List <TableViewModel> result = new List <TableViewModel>();

            using (var db = new KitchenContext())
            {
                result = (from d in db.Tables
                          select new TableViewModel
                {
                    id = d.id,
                    initial = d.initial,
                    Seat = d.Seat,
                    Desc = d.Desc,
                    Active = d.Active
                }).ToList();
            }
            return(result);
        }
Example #28
0
        public static ResponResultViewModel Update(ReservationVIewModel entity)
        {
            ResponResultViewModel result = new ResponResultViewModel();

            entity.reference = GerReff();
            try
            {
                using (var db = new KitchenContext())
                {
                    if (entity.id == 0)
                    {
                        Reservation reserv = new Reservation();
                        reserv.guest      = entity.guest;
                        reserv.reference  = entity.reference;
                        reserv.tableid    = entity.tableid;
                        reserv.Paid       = false;
                        reserv.CreateBy   = "Floofloo";
                        reserv.CreateDate = DateTime.Now;
                        reserv.Active     = true;
                        db.Reservations.Add(reserv);
                        db.SaveChanges();
                        result.Entity = entity;
                    }
                    else
                    {
                        Reservation reserv = db.Reservations.Where(r => r.id == entity.id).FirstOrDefault();
                        reserv.guest = entity.guest;

                        reserv.ModifyBy   = "BlubluRese";
                        reserv.ModifyDate = DateTime.Now;

                        db.SaveChanges();

                        result.Entity = entity;
                    }
                }
            }
            catch (Exception ee)
            {
                result.Success = false;
                result.Message = ee.Message;
            }
            return(result);
        }
Example #29
0
        public IEnumerable <Recipe> CalculateRecipesFromAvailableIngredients()
        {
            using (var context = new KitchenContext())
            {
                var recipes = _recipeReader.GetRecipes(context).ToList();
                var availableIngredients = _ingredientReader.GetIngredients(context).Where(x => x.Quantity > 0).ToList();

                foreach (var recipe in recipes)
                {
                    foreach (var ingredient in recipe.Ingredients)
                    {
                        if (!availableIngredients.Contains(ingredient))
                        {
                            recipes.Remove(recipe);
                        }
                    }
                }

                return(recipes);
            }
        }
Example #30
0
        public override bool IsUserInRole(string Login, string roleName)
        {
            bool outputResult = false;

            // Находим пользователя
            using (KitchenContext db = new KitchenContext())
            {
                // Получаем пользователя
                User user = db.Users.FirstOrDefault(u => u.Login == Login);
                if (user != null)
                {
                    // получаем роль
                    Role userRole = db.Roles.Find(user.RoleId);
                    //сравниваем
                    if (userRole != null && userRole.Name == roleName)
                    {
                        outputResult = true;
                    }
                }
            }
            return(outputResult);
        }