public static bool Insert(string menuItemname, int menuID, decimal price, string picture, int menusectionID, string desc)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblMenuItem newRow = new TblMenuItem()
             {
                 ItemID        = rc.TblMenuItems.Any() ? rc.TblMenuItems.Max(u => u.ItemID) + 1 : 1,
                 MenuID        = menuID,
                 ItemName      = menuItemname,
                 Price         = price,
                 Picture       = picture,
                 Description   = desc,
                 MenuSectionID = menusectionID
             };
             rc.TblMenuItems.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
        public static bool Deactivate(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        TblMenu tblMenu = rc.TblMenus.FirstOrDefault(u => u.MenuID == id);

                        if (tblMenu != null)
                        {
                            tblMenu.IsActive = false;

                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Menu was not found");
                        }
                    }
                }
                else
                {
                    throw new Exception("Must have a valid id");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <MenuItemModel> GetMenuItems(int menuID)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var TblMenuItems = rc.TblMenuItems.Where(w => menuID == w.MenuID).ToList();

                    if (TblMenuItems != null)
                    {
                        List <MenuItemModel> menuItems = new List <MenuItemModel>();

                        TblMenuItems.ForEach(u => menuItems.Add(new MenuItemModel
                        {
                            ItemID        = u.ItemID,
                            MenuItem      = u.MenuID,
                            ItemName      = u.ItemName,
                            Price         = u.Price,
                            Picture       = u.Picture,
                            Description   = u.Description,
                            MenuSectionID = u.MenuSectionID
                        }));

                        return(menuItems);
                    }

                    throw new Exception("There currently are no menuItems");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public static MenuItemModel Insert(MenuItemModel menuItem)/*,int menuItem, string itemName,
                                                            * int price,string picture,string description,int menuSectionID)*/
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblMenuItem newRow = new TblMenuItem()
             {
                 ItemID        = rc.TblMenuItems.Any() ? rc.TblMenuItems.Max(u => u.ItemID) + 1 : 1,
                 ItemName      = menuItem.ItemName,
                 MenuID        = menuItem.MenuItem,
                 Price         = menuItem.Price,
                 Picture       = menuItem.Picture,
                 Description   = menuItem.Description,
                 MenuSectionID = menuItem.MenuSectionID
             };
             rc.TblMenuItems.Add(newRow);
             rc.SaveChanges();
             menuItem.ItemID = newRow.ItemID;
             return(menuItem);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        // Unit tests only
        public static bool Delete(int ID)
        {
            try
            {
                if (ID != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var vendorEmployee = rc.TblVendorEmployees.FirstOrDefault(u => u.ID == ID);

                        if (vendorEmployee != null)
                        {
                            rc.TblVendorEmployees.Remove(vendorEmployee);
                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("VendorEmployee cannot be found");
                        }
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static VendorEmployeeModel GetVendorEmployee(int ID)
        {
            try
            {
                if (ID != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var tblVendorEmployee = rc.TblVendorEmployees.FirstOrDefault(u => u.ID == ID);

                        if (tblVendorEmployee != null)
                        {
                            VendorEmployeeModel vendorEmployee = new VendorEmployeeModel
                            {
                                ID       = tblVendorEmployee.ID,
                                UserID   = tblVendorEmployee.UserID,
                                VendorID = tblVendorEmployee.VendorID
                            };

                            return(vendorEmployee);
                        }

                        throw new Exception("VendorEmployee cannot be found");
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public static bool Insert(int Rating, string Subject, string Body)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblReview newRow = new TblReview()
             {
                 ReviewID = rc.TblReviews.Any() ? rc.TblReviews.Max(u => u.ReviewID) + 1 : 1,
                 VendorID = 1,
                 UserID   = 1,
                 Rating   = Rating,
                 Subject  = Subject,
                 Body     = Body
             };
             rc.TblReviews.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #8
0
        public static List <UserModel> GetUsers()
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblUsers = rc.TblUsers.ToList();

                    if (tblUsers != null)
                    {
                        List <UserModel> users = new List <UserModel>();

                        tblUsers.ForEach(u => users.Add(new UserModel {
                            UserID = u.UserID, Email = u.Email, FirstName = u.FirstName, LastName = u.LastName, Deactivated = u.Deactivated, DOB = (DateTime)u.DOB, Phone = u.Phone
                        }));

                        return(users);
                    }

                    throw new Exception("There currently are no users");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <ReviewModel> GetReviews(int VendorId)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblReview = rc.TblReviews.Where(r => r.VendorID == VendorId).ToList();

                    if (tblReview != null)
                    {
                        List <ReviewModel> reviews = new List <ReviewModel>();

                        tblReview.ForEach(u => reviews.Add(new ReviewModel {
                            ReviewID = u.ReviewID, VendorID = u.VendorID, UserID = u.UserID, Subject = u.Subject, Body = u.Body, Rating = u.Rating
                        }));

                        return(reviews);
                    }

                    throw new Exception("There currently are no reviews");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #10
0
        // Unit tests only
        public static bool Delete(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var review = rc.TblReviews.FirstOrDefault(u => u.ReviewID == id);

                        if (review != null)
                        {
                            rc.TblReviews.Remove(review);
                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Review cannot be found");
                        }
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
        public static OrderModel Insert(OrderModel order)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    PL.TblOrder newRow = new TblOrder()
                    {
                        OrderID   = rc.TblOrders.Any() ? rc.TblOrders.Max(u => u.OrderID) + 1 : 1,
                        VendorID  = order.VendorID,
                        UserID    = order.UserID,
                        OrderDate = order.OrderDate
                    };

                    order.OrderID = newRow.OrderID;
                    rc.TblOrders.Add(newRow);
                    rc.SaveChanges();
                    return(order);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #12
0
        public static List <OrderModel> GetUserOrders(int UserID)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblOrders = rc.TblOrders.Where(w => UserID == w.UserID).ToList();

                    if (tblOrders != null)
                    {
                        List <OrderModel> orders = new List <OrderModel>();

                        tblOrders.ForEach(u => orders.Add(new OrderModel {
                            OrderID   = u.OrderID,
                            VendorID  = u.VendorID,
                            UserID    = u.UserID,
                            OrderDate = u.OrderDate
                        }));

                        return(orders);
                    }

                    throw new Exception("The user currently has no orders");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #13
0
 public static bool Insert(int OwnerID, string CompanyName, string CompanyEmail, DateTime InspectionDate, string Bio, string Website)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblVendor newRow = new TblVendor()
             {
                 VendorID       = rc.TblVendors.Any() ? rc.TblVendors.Max(v => v.VendorID) + 1 : 1,
                 OwnerID        = OwnerID,
                 CompanyName    = CompanyName,
                 CompanyEmail   = CompanyEmail,
                 InspectionDate = InspectionDate,
                 Bio            = Bio,
                 Website        = Website,
                 Confirmed      = false
             };
             rc.TblVendors.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #14
0
 public static bool Insert(VendorModel vendor)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblVendor newRow = new TblVendor()
             {
                 VendorID       = rc.TblVendors.Any() ? rc.TblVendors.Max(v => v.VendorID) + 1 : 1,
                 OwnerID        = vendor.OwnerID,
                 CompanyName    = vendor.CompanyName,
                 CompanyEmail   = vendor.CompanyEmail,
                 LicenseNumber  = vendor.LicenseNumber,
                 InspectionDate = vendor.InspectionDate,
                 Bio            = vendor.Bio,
                 Website        = vendor.Website,
                 Confirmed      = false
             };
             rc.TblVendors.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static List <VendorEmployeeModel> GetVendorEmployees(int vendorId)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblVendorEmployee = rc.TblVendorEmployees.Where(v => v.VendorID == vendorId).ToList();

                    if (tblVendorEmployee != null)
                    {
                        List <VendorEmployeeModel> vendorEmployees = new List <VendorEmployeeModel>();

                        tblVendorEmployee.ForEach(u => vendorEmployees.Add(new VendorEmployeeModel {
                            ID = u.ID, VendorID = u.VendorID, UserID = u.UserID
                        }));

                        return(vendorEmployees);
                    }

                    throw new Exception("There currently are no vendorEmployees");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #16
0
 public static bool Insert(string Email, string firstname, string lastname, string Password, string Phone)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblUser newRow = new TblUser()
             {
                 UserID    = rc.TblUsers.Any()? rc.TblUsers.Max(u => u.UserID) + 1: 1,
                 Email     = Email,
                 FirstName = firstname,
                 LastName  = lastname,
                 Password  = Password,
                 Phone     = Phone
             };
             rc.TblUsers.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #17
0
        public static MenuModel GetMenu(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var tblMenu = rc.TblMenus.FirstOrDefault(u => u.MenuID == id);

                        if (tblMenu != null)
                        {
                            MenuModel menu = new MenuModel
                            {
                                MenuID   = tblMenu.MenuID,
                                VendorID = tblMenu.VendorID,
                                IsActive = tblMenu.IsActive
                            };

                            return(menu);
                        }

                        throw new Exception("Menu cannot be found");
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // Unit tests only
        public static bool Delete(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var menuSection = rc.TblMenuSections.FirstOrDefault(u => u.MenuSectionID == id);

                        if (menuSection != null)
                        {
                            rc.TblMenuSections.Remove(menuSection);
                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Menu section cannot be found");
                        }
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #19
0
        public static List <VendorModel> GetVendors()
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblVendors = rc.TblVendors.ToList();

                    if (tblVendors != null)
                    {
                        List <VendorModel> vendors = new List <VendorModel>();

                        tblVendors.ForEach(v => vendors.Add(new VendorModel {
                            VendorID = v.VendorID, OwnerID = v.OwnerID, CompanyName = v.CompanyName, CompanyEmail = v.CompanyEmail, LicenseNumber = v.LicenseNumber, InspectionDate = v.InspectionDate, Bio = v.Bio, Website = v.Website, Confirmed = v.Confirmed
                        }));

                        return(vendors);
                    }

                    throw new Exception("There currently are no vendors");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <MenuSectionModel> GetMenuSections(int menuID)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblMenuSection = rc.TblMenuSections.Where(m => m.MenuID == menuID).ToList();

                    if (tblMenuSection != null)
                    {
                        List <MenuSectionModel> menuSections = new List <MenuSectionModel>();

                        tblMenuSection.ForEach(u => menuSections.Add(new MenuSectionModel {
                            MenuSectionID = u.MenuSectionID, MenuID = u.MenuID, DisplayOrderNum = u.DisplayOrderNum, MenuSectionName = u.MenuSectionName
                        }));

                        return(menuSections);
                    }

                    throw new Exception("There currently are no menu sections");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Update(MenuSectionModel menuSection)
        {
            try
            {
                if (menuSection.MenuSectionID != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        TblMenuSection tblMenuSection = rc.TblMenuSections.FirstOrDefault(u => u.MenuSectionID == menuSection.MenuSectionID);

                        if (tblMenuSection != null)
                        {
                            tblMenuSection.DisplayOrderNum = menuSection.DisplayOrderNum;
                            tblMenuSection.MenuSectionName = menuSection.MenuSectionName;
                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Menu section was not found");
                        }
                    }
                }
                else
                {
                    throw new Exception("Must have a valid ID");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Delete(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var cuisine = rc.TblCuisines.FirstOrDefault(u => u.CuisineID == id);

                        if (cuisine != null)
                        {
                            rc.TblCuisines.Remove(cuisine);
                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Item cannot be found");
                        }
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <CuisineModel> GetCuisines(int VendorID)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblCuisines = rc.TblCuisines.Where(w => VendorID == w.VendorID).ToList();

                    if (tblCuisines != null)
                    {
                        List <CuisineModel> cuisines = new List <CuisineModel>();

                        tblCuisines.ForEach(u => cuisines.Add(new CuisineModel {
                            CuisineID = u.CuisineID, MenuID = u.MenuID,
                            VendorID  = u.VendorID, CuisineName = u.CuisineName
                        }));

                        return(cuisines);
                    }

                    throw new Exception("There currently are no cuisines");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // Unit tests only
        public static bool Delete(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var vendorLocation = rc.TblVendorLocations.FirstOrDefault(v => v.VendorID == id);

                        if (vendorLocation != null)
                        {
                            rc.TblVendorLocations.Remove(vendorLocation);
                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Vendor cannot be found");
                        }
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static VendorLocationModel GetVendorLocation(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var tblVendorLocation = rc.TblVendorLocations.FirstOrDefault(v => v.VendorID == id);

                        if (tblVendorLocation != null)
                        {
                            VendorLocationModel vendorLocation = new VendorLocationModel
                            {
                                VendorID  = tblVendorLocation.VendorID,
                                LocationX = tblVendorLocation.LocationX,
                                LocationY = tblVendorLocation.LocationY,
                                Date      = (DateTime)tblVendorLocation.Datetime
                            };
                            return(vendorLocation);
                        }
                        throw new Exception("Vendor location cannot be found");
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <VendorLocationModel> GetVendorLocations()
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblVendorLocations = rc.TblVendorLocations.ToList();

                    if (tblVendorLocations != null)
                    {
                        List <VendorLocationModel> vendorLocations = new List <VendorLocationModel>();

                        tblVendorLocations.ForEach(v => vendorLocations.Add(new VendorLocationModel {
                            VendorID = v.VendorID, LocationX = v.LocationX, LocationY = v.LocationY, Date = (DateTime)v.Datetime
                        }));

                        return(vendorLocations);
                    }

                    throw new Exception("There currently are no vendors");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <OrderItemModel> GetOrderItems(int menuID)
        {
            try
            {
                using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                {
                    var tblOrderItems = rc.TblOrderItems.Where(w => menuID == w.MenuItemId).ToList();

                    if (tblOrderItems != null)
                    {
                        List <OrderItemModel> orderItems = new List <OrderItemModel>();

                        tblOrderItems.ForEach(u => orderItems.Add(new OrderItemModel {
                            OrderItemID = u.OrderItemID, MenuItemID = u.MenuItemId, Price = u.Price, Quantity = u.Quantity
                        }));

                        return(orderItems);
                    }

                    throw new Exception("There currently are no orderItems");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #28
0
 public static bool Insert(UserModel user)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblUser newRow = new TblUser()
             {
                 UserID      = rc.TblUsers.Any()? rc.TblUsers.Max(u => u.UserID) + 1: 1,
                 Email       = user.Email,
                 FirstName   = user.FirstName,
                 LastName    = user.LastName,
                 DOB         = user.DOB,
                 Password    = GetHash(user.Password).ToString(),
                 Phone       = user.Phone,
                 Deactivated = user.Deactivated,
                 Admin       = user.Admin
             };
             rc.TblUsers.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #29
0
        public static bool Deactivate(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        TblUser tblUser = rc.TblUsers.FirstOrDefault(u => u.UserID == id);

                        if (tblUser != null)
                        {
                            tblUser.Deactivated = true;
                            tblUser.Admin       = false;
                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("User was not found");
                        }
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #30
0
        public static bool Login(UserModel user)
        {
            try
            {
                if (!string.IsNullOrEmpty(user.Email))
                {
                    if (!string.IsNullOrEmpty(user.Password))
                    {
                        using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                        {
                            string  hashPassword = GetHash(user.Password).ToString();
                            TblUser tblUser      = rc.TblUsers.FirstOrDefault(u => u.Email == user.Email && u.Password == hashPassword);


                            if (tblUser != null && tblUser.Deactivated == false)
                            {
                                user.UserID      = tblUser.UserID;
                                user.FirstName   = tblUser.FirstName;
                                user.LastName    = tblUser.LastName;
                                user.Deactivated = tblUser.Deactivated;
                                user.DOB         = (DateTime)tblUser.DOB;
                                user.Admin       = tblUser.Admin;

                                return(true);
                            }

                            throw new Exception("Email/Password combination doesn't match any users");
                        }
                    }
                    else
                    {
                        throw new Exception("Password cannot be empty");
                    }
                }
                else
                {
                    throw new Exception("Email cannot be empty");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }