示例#1
0
        public static List <RentALanguageTeacher.App_Code.Time.TimeZoneDDL> FillTimeZoneDDL(string CountryCode)
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    // get user
                    var MyObjects = (from s in ctx.zones
                                     where s.country_code_iso2 == CountryCode
                                     orderby s.zone_name
                                     select new RentALanguageTeacher.App_Code.Time.TimeZoneDDL()
                    {
                        ZoneId = s.zone_id, ZoneName = s.zone_name
                    });

                    //log
                    if (object.ReferenceEquals(MyObjects, null))
                    {
                        log.Debug(MethodName + "() - No Objects were returned");
                        return(null);
                    }

                    else
                    {
                        log.Debug(MethodName + "() - Returned results");
                        return(MyObjects.ToList());
                    }
                }

                catch (NullReferenceException e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }
        public static quickregistration GetObjectByUserId(int UserId)
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                ctx.Configuration.ProxyCreationEnabled = false;

                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    // get user
                    var MyObject = (from s in ctx.quickregistrations
                                    where s.user_id == UserId
                                    select s).FirstOrDefault <quickregistration>();

                    //log
                    if (!object.ReferenceEquals(MyObject, null))
                    {
                        log.Debug(MethodName + "() - The item for ID " + UserId + " was returned");
                    }

                    else
                    {
                        log.Debug(MethodName + "() - The item for ID " + UserId + " returned 0 results");
                    }

                    return(MyObject);
                }

                catch (NullReferenceException e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }
        public static zone GetObjectByUserId(int ID)
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    // get user
                    var MyObject = (from s in ctx.zones
                                    where s.zone_id == ID
                                    select s).FirstOrDefault <zone>();

                    //log
                    if (!object.ReferenceEquals(MyObject, null))
                    {
                        log.Debug(MethodName + "() - The item for ID " + ID + " was returned");
                    }

                    else
                    {
                        log.Debug(MethodName + "() - The item for ID " + ID + " returned 0 results");
                    }

                    return(MyObject);
                }

                catch (NullReferenceException e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }
        public static List <payment> GetObjectsByUserId(int UserId)
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    // get user
                    var MyObjects = (from s in ctx.payments
                                     where s.user_id == UserId
                                     select s);

                    //log
                    if (!object.ReferenceEquals(MyObjects, null))
                    {
                        log.Debug(MethodName + "() - The item for ID " + UserId + " was returned");
                    }

                    else
                    {
                        log.Debug(MethodName + "() - The item for ID " + UserId + " returned 0 results");
                    }

                    return(MyObjects.ToList());
                }

                catch (NullReferenceException e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }
        public static int SaveObject(quickregistration MyObject)
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    //Check object state, add or update

                    if (MyObject.quick_registration_id == 0)
                    {
                        //Add new object
                        ctx.quickregistrations.Add(MyObject);
                        log.Debug(MethodName + "() - New object added");
                    }

                    else
                    {
                        //Update object
                        ctx.Entry(MyObject).State = System.Data.EntityState.Detached;
                        ctx.Entry(MyObject).State = System.Data.EntityState.Modified;
                        // log.Debug(MethodName + "() - The object for ID " + MyObject.quick_registration_id + " was updated");
                    }

                    //save context changes
                    int num = ctx.SaveChanges();

                    //return?
                    return(num);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }
        public static int GetCount()
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    // get user
                    var MyObject = ctx.wordofdays.Count();

                    //log
                    if (!object.ReferenceEquals(MyObject, null))
                    {
                        log.Debug(MethodName + "() - The item for ID " + " was returned");
                    }

                    else
                    {
                        log.Debug(MethodName + "() - The item for ID " + " returned 0 results");
                    }

                    return(MyObject);
                }

                catch (NullReferenceException e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }
        public static int DeleteObject(quickregistration MyObject)
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    ctx.Entry(MyObject).State = System.Data.EntityState.Deleted;

                    //Delete user
                    ctx.quickregistrations.Remove(MyObject);

                    //save context changes
                    int num = ctx.SaveChanges();

                    //return?
                    return(num);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }
        public static List <Student> GetStudents()
        {
            //get method name
            string MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            //initialize entities
            var ctx = new rentalanguageteacherEntities();
            {
                try
                {
                    log.Debug(MethodName + "**********************************************************************************************************");
                    log.Debug(MethodName + "() - Start");

                    // get user
                    var Query = (from s in ctx.users
                                 orderby s.member_id
                                 select s).Include(s => s.my_aspnet_membership).Include(s => s.my_aspnet_users).Include(s => s.locations);

                    var MyObjects = (from s in Query
                                     select new RentALanguageTeacher.App_Code.Student()
                    {
                        UserName = s.my_aspnet_users.name, Name = s.first_name + " " + s.last_name, Status = s.account_status, Email = s.my_aspnet_membership.Email
                    });
                    //select new RentALanguageTeacher.App_Code.Student() { UserName = s.my_aspnet_users.name, Name = s.first_name + " " + s.last_name, Status=s.account_status, TimeZone=s.locations.OfType<location>().FirstOrDefault().zone.zone_name });
                    //.Include(s => s.my_aspnet_membership).Include(s => s.my_aspnet_users).Include(s => s.locations);

                    //log
                    if (!object.ReferenceEquals(MyObjects, null))
                    {
                        log.Debug(MethodName + "() - The item for ID " + "null" + " was returned");
                    }

                    else
                    {
                        log.Debug(MethodName + "() - The item for ID " + "null" + " returned 0 results");
                    }

                    return(MyObjects.ToList());
                }

                catch (NullReferenceException e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                catch (Exception e)
                {
                    log.Error(MethodName + "() - " + e.Message);
                    log.Debug(MethodName + "() - " + e.StackTrace);
                    throw (e);
                }

                finally
                {
                    log.Debug(MethodName + "() - Finish");
                    log.Debug(MethodName + "**********************************************************************************************************");
                }
            }
        }