Exemplo n.º 1
0
        public Result <Course> AddNewCourse(Course newCourse)
        {
            int NumOfRecords = 0;

            /* Create the result object ; which will be returned at the end
             * of the method */
            Result <Course> result = new Result <Course>();

            try
            {
                //List<String> listOfCourses = dbConn.catalogs
                //    .Where(c => c.Description.Equals(newCourse.CourseName)
                //                && c.Category.Equals("Courses"))
                //    .Select(d => d.Description)
                //    .Distinct().ToList<String>();
                List <String> listOfCourses = dbConn.Courses
                                              .Where(c => c.CourseName.Equals(newCourse.CourseName))
                                              .Select(d => d.CourseName)
                                              .Distinct().ToList <String>();



                if (listOfCourses == null || listOfCourses.Count == 0)
                {
                    newCourse.isDeleted = "F";
                    dbConn.Courses.Add(newCourse);

                    NumOfRecords = dbConn.SaveChanges();
                    /* if there is at least 1 record saved -> true, if not -> false */
                    if (NumOfRecords >= 1)
                    {
                        result.isSuccess    = true;
                        result.message      = "Course added successfully";
                        result.resultObject = newCourse;
                    }
                    else
                    {
                        result.isSuccess = false;
                        result.message   = "Error in adding course";
                    }
                }
                else
                {
                    result.isSuccess = false;
                    result.message   = "Course name '" + newCourse.CourseName + "' already exists";
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            return(result);
        }
Exemplo n.º 2
0
        public Result <Object> UpdateCatalogItem(Catalog catalogItem)
        {
            int NumOfRecords = 0;

            /* Create the result object ; which will be returned at the end
             * of the method */
            Result <Object> result = new Result <Object>();

            try
            {
                /* Database Connection */
                dbCon = new OlescEntities();

                Catalog item = dbCon.Catalogs.Where(c => c.ID == catalogItem.ID).FirstOrDefault();
                if (item != null)
                {
                    item.Description = catalogItem.Description;
                    item.Category    = catalogItem.Category;
                    item.ParentID    = catalogItem.ParentID;

                    /*After debug, this was the issue of adding after update*/
                    //dbCon.Catalogs.Add(catalogItem);

                    NumOfRecords = dbCon.SaveChanges();
                    /* if there is at least 1 record saved -> true, if not -> false */
                    if (NumOfRecords >= 1)
                    {
                        result.isSuccess = true;
                        result.message   = "Updated successfully";
                    }
                    else
                    {
                        result.isSuccess = false;
                        result.message   = "Error updating";
                    }
                }
                else
                {
                    result.isSuccess = false;
                    result.message   = "Catalog Item does not exist";
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            return(result);
        }
Exemplo n.º 3
0
        public Result <Object> AddCatalogItem(Catalog newCatalogItem)
        {
            int NumOfRecords = 0;

            /* Create the result object ; which will be returned at the end
             * of the method */
            Result <Object> result = new Result <Object>();

            /* Database Connection */


            try
            {
                dbCon.Catalogs.Add(newCatalogItem);

                NumOfRecords = dbCon.SaveChanges();
                /* if there is at least 1 record saved -> true, if not -> false */
                if (NumOfRecords >= 1)
                {
                    result.isSuccess = true;
                    result.message   = newCatalogItem.Description + " was added sucessfully";
                }
                else
                {
                    result.isSuccess = false;
                    result.message   = newCatalogItem.Description + " was not added";
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            return(result);
        }
Exemplo n.º 4
0
        public Result <UserProfile> UpdateUserProfile(UserProfile userprofile)
        {
            /* Create the result object ; which will be returned at the end
             * of the method */
            Result <UserProfile> result = new Result <UserProfile>();

            try
            {
                Result <UserProfile> userProfileResult = GetUserProfile(userprofile.UserID);
                if (userProfileResult.isSuccess)
                {
                    userProfileResult.resultObject.FirstName   = userprofile.FirstName;
                    userProfileResult.resultObject.LastName    = userprofile.LastName;
                    userProfileResult.resultObject.College     = userprofile.College;
                    userProfileResult.resultObject.Major       = userprofile.Major;
                    userProfileResult.resultObject.CreatedBy   = userprofile.CreatedBy;
                    userProfileResult.resultObject.CreatedDate = userprofile.CreatedDate;
                    userProfileResult.resultObject.UpdatedBy   = userprofile.UpdatedBy;
                    userProfileResult.resultObject.UpdatedDate = DateTime.Now;
                    int numRecords = dbConn.SaveChanges();
                    if (numRecords > 0)
                    {
                        result.isSuccess    = true;
                        result.message      = "User profile updated.";
                        result.resultObject = userProfileResult.resultObject;
                    }
                    else
                    {
                        result.isSuccess = false;
                        result.message   = "changes have not been saved.";
                    }
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            return(result);
        }
Exemplo n.º 5
0
        private Result <OlescUser> ChangeUserStatus(String username, UserStatus userStatus, String loggedInUser)
        {
            /* Create the result object ; which will be returned at the end
             * of the method */
            Result <OlescUser> result = new Result <OlescUser>();

            try
            {
                /* Log stores any activity occured, like log book */
                /* Database has log method*/
                /* Informational Log */
                // dbCon.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
                /* Get User Object*/

                /* Using a method getUser to get the user*/
                Result <OlescUser> getUserResult = GetUser(username);

                //Convert the User Status from Char to String (A/I)
                String newUserStatus = ((char)userStatus).ToString();

                /* check if getUserSuccessfuly*/
                if (getUserResult != null && getUserResult.isSuccess)
                {
                    OlescUser user = getUserResult.resultObject;

                    /* Check if the user exists in the database*/
                    if (user != null)
                    {
                        if (user.isActive.Equals(newUserStatus))
                        {
                            switch (userStatus)
                            {
                            case UserStatus.Active:
                                result.message = "User \"" + username + "\" is already active";
                                break;

                            case UserStatus.InActive:
                                result.message = "User \"" + username + "\" is already inactive";
                                break;
                            }
                        }
                        else
                        {
                            user.isActive    = newUserStatus;
                            user.UpdatedBy   = loggedInUser;
                            user.UpdatedDate = DateTime.Now;

                            int records = 0;
                            records = dbCon.SaveChanges();
                            if (records > 0)
                            {
                                result.isSuccess = true;

                                switch (userStatus)
                                {
                                case UserStatus.Active:
                                    result.message = "User \"" + username + "\" has been Actived";
                                    break;

                                case UserStatus.InActive:
                                    result.message = "User \"" + username + "\" has been Deactivated";
                                    break;
                                }

                                result.resultObject = user;
                            }
                            else
                            {
                                result.isSuccess = false;
                                result.message   = "No Users were activated/deactivated";
                            }
                        }
                    }
                    else
                    {
                        result.message   = "User Not found";
                        result.isSuccess = false;
                    }
                }
                else
                {
                    result.message   = "Error Fetching User";
                    result.isSuccess = false;
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            //finally
            //{

            //}
            return(result);
        }
Exemplo n.º 6
0
        public Result <object> RateTutor(int studentID, int sessionID, double rate)
        {
            Result <object> result;

            result = new Result <object>();

            try
            {
                SessionStudent ss = dbConn.SessionStudents.Where(s => s.StudentID.Equals(studentID) &&
                                                                 s.SessionID.Equals(sessionID)).FirstOrDefault();

                /*Session for student exists*/
                if (ss != null)
                {
                    /*
                     * 1- Session is Active
                     * 2- Session has started
                     * 3- Session has ended
                     */
                    if (ss.Session.Status.Equals("A") &&
                        DateTime.Compare(ss.Session.StartDateTime, DateTime.Now) < 0 &&
                        DateTime.Compare(ss.Session.EndDateTime, DateTime.Now) < 0)
                    {
                        /* Rating value is within range */
                        if (rate <= Constants.MAX_RATE_VALUE && rate >= Constants.MIN_RATE_VALUE)
                        {
                            ss.Rate = (Decimal)rate;
                            // ss.Rate = Decimal.Parse(rate.ToString());
                            ss.RateDate = DateTime.Now;
                            int NumOfRecords = dbConn.SaveChanges();
                            if (NumOfRecords >= 1)
                            {
                                result.isSuccess = true;
                                result.message   = "Tutor is rated succesfully";
                            }
                            else
                            {
                                result.isSuccess = false;
                                result.message   = "Error in Rating, please check";
                            }
                        }
                        else
                        {
                            result.isSuccess = false;
                            result.message   = "Invalid rate value";
                        }
                    }
                    else
                    {
                        result.isSuccess = false;
                        result.message   = "Session is not Active";
                    }
                }
                else
                {
                    result.isSuccess = false;
                    result.message   = "Student does not belong to the session";
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }

            return(result);
        }
Exemplo n.º 7
0
        public Result <OlescUser> Register(OlescUser newUser, UserProfile newUserProfile, List <OlescRole> roles)
        {
            int NumOfRecords = 0;

            /* Create the result object ; which will be returned at the end
             * of the method */
            Result <OlescUser> result = new Result <OlescUser>();
            /* Database Connection */
            OlescEntities dbCon = null;

            try
            {
                /* Database Connection */
                dbCon = new OlescEntities();

                /* Adding a newUser to User table,
                 * and returns the object with user ID */
                newUser.isActive = "A";

                /* Take the user password and turn in into MD5 hash,
                 * then save the hash in the database */
                newUser.Password = StringUtility.CreateMD5Hash(newUser.Password);

                newUser = dbCon.OlescUsers.Add(newUser);

                /* assign ID to UserProfile table; because it's PF */
                //newUserProfile.UserID = newUser.ID;
                newUserProfile.user = newUser;

                /* Adding a newUserProfile to UserProfile table,
                 * and returns the object */
                newUserProfile = dbCon.UserProfiles.Add(newUserProfile);

                foreach (OlescRole role in roles)
                {
                    /* creating an object for userrole, using userrole table */
                    OlescUserRole newUserRole = new OlescUserRole();

                    /* What I need to assign a role is to have RoleID and UserID
                     * "Check database table UserRole"*/
                    //newUserRole.UserID = newUser.ID;
                    newUserRole.User   = newUser;
                    newUserRole.RoleID = role.ID;

                    /*Adding the role assigned tp userRole table*/
                    newUserRole = dbCon.OlescUserRoles.Add(newUserRole);
                }

                NumOfRecords = dbCon.SaveChanges();
                /* if there is at least 1 record saved -> true, if not -> false */
                if (NumOfRecords >= 1)
                {
                    result.isSuccess = true;
                    result.message   = "Thank you " + newUser.UserProfile.FirstName + " for regstering in OLESC!";


                    NotificationManagementService nms = new NotificationManagementService();

                    /* Email notification service */
                    /* Conent */
                    String emailContent;
                    emailContent  = "Thank you for registering in OLESC";
                    emailContent += "\nYour Username is your email: " + newUser.Email;
                    emailContent += "\nEnjoy our Online Learning Srvices!";
                    emailContent += "\n\nRegards,\nOLESC Team";

                    /* Subject*/
                    String emailSubject;
                    emailSubject = "OLESC Registration";

                    /* Sending the email */
                    nms.Notify(newUser.Email, null, null, emailSubject, emailContent);
                }
                else
                {
                    result.isSuccess = false;
                    result.message   = "Error in registration, please check you information";
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            /* Whatever you want to clean up, close after error to delete from memory*/
            finally
            {
                if (dbCon != null)
                {
                    /* Same as in Java dbCon.Close() */
                    dbCon.Dispose();
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        public Result <OlescUser> ChangePassword(string username, string password)
        {
            int NumOfRecords = 0;

            /* Create the result object ; which will be returned at the end
             * of the method */
            Result <OlescUser> result = new Result <OlescUser>();
            /* Database Connection */
            OlescEntities dbCon = null;

            try
            {
                /* Database Connection */
                dbCon = new OlescEntities();

                OlescUser user = dbCon.OlescUsers.Where(u => u.Email.Equals(username)).FirstOrDefault();
                if (user != null)
                {
                    password = StringUtility.CreateMD5Hash(password);

                    if (!user.Password.Equals(password))
                    {
                        user.Password = password;
                        NumOfRecords  = dbCon.SaveChanges();
                        /* if there is at least 1 record saved -> true, if not -> false */
                        if (NumOfRecords >= 1)
                        {
                            result.isSuccess = true;
                            result.message   = "Password changed successfully";

                            NotificationManagementService nms = new NotificationManagementService();

                            /* Email notification service */
                            /* Conent */
                            String emailContent;
                            emailContent  = "Dear " + user.UserProfile.FirstName;
                            emailContent += "\nThis email is notify you that your password has been changed.";
                            emailContent += "\nIf you haven't changed your password, please reset your password in the login page.";
                            emailContent += "\n\nRegards,\nOLESC Team";

                            /* Subject*/
                            String emailSubject;
                            emailSubject = "Your Password has been Changed";

                            /* Sending the email */
                            nms.Notify(user.Email, null, null, emailSubject, emailContent);
                        }
                        else
                        {
                            result.isSuccess = false;
                            result.message   = "Error changing password";
                        }
                    }
                    else
                    {
                        result.isSuccess = false;
                        result.message   = "Old password is the same as the new password";
                    }
                }
                else
                {
                    result.isSuccess = false;
                    result.message   = "User does not exist";
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            finally
            {
                if (dbCon != null)
                {
                    /* Same as in Java dbCon.Close() */
                    dbCon.Dispose();
                }
            }

            return(result);
        }