Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public static ResponResultViewModel Update(ProductViewModel entity)
        {
            //Untuk create dan edit
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new KitchenContext())
                {
                    //Create
                    if (entity.id == 0)
                    {
                        Product product = new Product();
                        product.initial     = entity.initial;
                        product.name        = entity.name;
                        product.description = entity.description;
                        product.categoryid  = entity.categoryid;
                        product.price       = entity.price;
                        product.Active      = entity.Active;


                        product.CreateBy   = "Bloblo";
                        product.CreateDate = DateTime.Now;
                        db.Products.Add(product);
                        db.SaveChanges();

                        result.Entity = product;
                    }
                    //Edit
                    else
                    {
                        Product product = db.Products.Where(o => o.id == entity.id).FirstOrDefault();
                        if (product != null)
                        {
                            product.initial     = entity.initial;
                            product.name        = entity.name;
                            product.description = entity.description;
                            product.categoryid  = entity.categoryid;
                            product.price       = entity.price;
                            product.Active      = entity.Active;

                            product.ModifyBy   = "Bloblo";
                            product.ModifyDate = DateTime.Now;

                            db.SaveChanges();

                            result.Entity = entity;
                        }
                        else
                        {
                            result.Success = false;
                            result.Message = "Prod not Found!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Esempio n. 8
0
        public static ResponResultViewModel Update(StudentViewModel entity)
        {
            //Untuk create dan edit
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new KitchenContext())
                {
                    //Create
                    if (entity.id == 0)
                    {
                        Student st = new Student();
                        st.firstname = entity.firstname;
                        st.lastname  = entity.lastname;
                        st.gender    = entity.gender;
                        st.dob       = entity.dob;
                        st.pob       = entity.pob;
                        st.Active    = entity.Active;

                        st.CreateBy   = "Blobloblo";
                        st.CreateDate = DateTime.Now;

                        db.Students.Add(st);
                        db.SaveChanges();

                        result.Entity = st;
                    }
                    //Edit
                    else
                    {
                        Student st = db.Students.Where(o => o.id == entity.id).FirstOrDefault();
                        if (st != null)
                        {
                            st.firstname = entity.firstname;
                            st.lastname  = entity.lastname;
                            st.gender    = entity.gender;
                            st.dob       = entity.dob;
                            st.pob       = entity.pob;
                            st.Active    = entity.Active;


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

                            db.SaveChanges();

                            result.Entity = entity;
                        }
                        else
                        {
                            result.Success = false;
                            result.Message = "Student not Found!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }