예제 #1
0
 public void Update_MenuItem(MenuItem item)
 {
     using (var context = new LeieveContext())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #2
0
 public void Add_MenuItem(MenuItem item)
 {
     using (var context = new LeieveContext())
     {
         context.MenuItems.Add(item);
         context.SaveChanges();
     }
 }
예제 #3
0
 public List <MenuItem> MenuItems_List()
 {
     using (var context = new LeieveContext())
     {
         var res = context.MenuItems;
         return(res.ToList());
     }
 }
 public List <ShoppingCartItemPOCO> List_ItemsForShoppingCart(int employeeid)
 {
     using (var context = new LeieveContext())
     {
         var results = (from x in context.ShoppingCarts
                        where x.EmployeeID.Equals(employeeid)
                        select x).FirstOrDefault();
     }
     return
 }
예제 #5
0
        public void Delete_MenuItem(MenuItem item)
        {
            using (var context = new LeieveContext())
            {
                var existing = context.MenuItems.Find(item.MenuItemID);


                context.MenuItems.Remove(existing);
                context.SaveChanges();
            }
        }
예제 #6
0
 public List <CategoryDTO> MenuByCategory_list()
 {
     using (var context = new LeieveContext())
     {
         var resualt = from x in context.Categories
                       orderby x.Description
                       select new CategoryDTO
         {
             Description = x.Description,
             MenuItems   = from y in x.MenuItems
                           orderby y.Description
                           select new MenuItemPOCO
             {
                 Itemid          = y.MenuItemID,
                 ItemDescription = y.Description,
                 Price           = y.SellingPrice
             }
         };
         return(resualt.ToList());
     }
 }
        public void AddDefaultUsers()
        {
            using (var context = new LeieveContext())
            {
                // Add a web  master user
                //Users accesses all the records on the AspNetUsers table
                //UserName is the user logon user id (dwelch)
                if (!Users.Any(u => u.UserName.Equals(STR_WEBMASTER_USERNAME)))
                {
                    var webMasterAccount = new ApplicationUser()
                    {
                        //create a new instance that will be used as the data to
                        //   add a new record to the AspNetUsers table
                        //dynamically fill two attributes of the instance
                        UserName = STR_WEBMASTER_USERNAME,
                        Email    = string.Format(STR_EMAIL_FORMAT, STR_WEBMASTER_USERNAME)
                    };
                    //place the webmaster account on the AspNetUsers table
                    this.Create(webMasterAccount, STR_DEFAULT_PASSWORD);
                    //place an account role record on the AspNetUserRoles table
                    //.Id comes from the webmasterAccount and is the pkey of the Users table
                    //role will comes from the Entities.Security.SecurityRoles
                    this.AddToRole(webMasterAccount.Id, SecurityRoles.WebsiteAdmins);
                }
                //get all current employees
                //linq query will not execute as yet
                //return datatype will be IQueryable<EmployeeListPOCO>
                var currentEmployees = from x in context.Employees
                                       select new EmployeeListPOCO
                {
                    EmployeeId = x.EmployeeID,
                    FirstName  = x.FirstName,
                    LastName   = x.LastName
                };
                //get all employees who have an user account
                //Users needs to be in memory therfore use .ToList()
                //POCO EmployeeID is an int
                //the Users Employee id is an int?
                //since we will only be retrieving
                //  Users that are employees (ID is not null)
                //  we need to convert the nullable int into
                //  a require int
                //the results of this query will be in memory
                var UserEmployees = from x in Users.ToList()
                                    where x.EmployeeID.HasValue
                                    select new RegisteredEmployeePOCO
                {
                    UserName   = x.UserName,
                    EmployeeId = int.Parse(x.EmployeeID.ToString())
                };
                //loop to see if auto generation of new employee
                //Users record is needed
                //the foreach cause the delayed execution of the
                //linq above
                foreach (var employee in currentEmployees)

                {
                    //does the employee NOT have a logon (no User record)

                    if (!UserEmployees.Any(us => us.EmployeeId == employee.EmployeeId))

                    {
                        //create a suggested employee UserName

                        //firstname initial + LastName: dwelch

                        var newUserName = employee.FirstName.Substring(0, 1) + employee.LastName;



                        //create a new User ApplicationUser instance

                        var userAccount = new ApplicationUser()

                        {
                            UserName = newUserName,

                            Email = string.Format(STR_EMAIL_FORMAT, newUserName),

                            EmailConfirmed = true
                        };

                        userAccount.EmployeeID = employee.EmployeeId;

                        //create the Users record

                        IdentityResult result = this.Create(userAccount, STR_DEFAULT_PASSWORD);



                        //result hold the return value of the creation attempt

                        //if true, account was created,

                        //if false, an account already exists with that username

                        if (!result.Succeeded)

                        {
                            //name already in use

                            //get a UserName that is not in use

                            newUserName = VerifyNewUserName(newUserName);

                            userAccount.UserName = newUserName;

                            this.Create(userAccount, STR_DEFAULT_PASSWORD);
                        }



                        //create the staff role in UserRoles

                        this.AddToRole(userAccount.Id, SecurityRoles.Staff);
                    }
                }
            }
        }