Пример #1
0
        public ActionResult Edit(EditModel model)
        {
            if (ModelState.IsValid)
            {
                // Update the user in the MySQL DB
                String        oldEmail = User.Identity.Name;
                DBAccessor    dba      = new DBAccessor();
                LogonResponse result   = dba.CheckLoginCredentials(oldEmail, model.Password);

                if (result.success == (int)LogonResults.SUCCESS)
                {
                    Person updateUser = new Person(model.FirstName, model.LastName, model.Email, model.ImageURL, "", model.Birthday, model.Height, model.Weight);
                    dba.UpdateUserInformation(oldEmail, updateUser);

                    // Set the appropriate cookies
                    FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */);
                    HttpCookie cookie = new HttpCookie(AppConstants.COOKIE_NAME, model.FirstName + " " + model.LastName);
                    cookie.Expires = DateTime.Now.AddDays(1000);
                    this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
                }
                else
                {
                    ModelState.AddModelError("", result.errorMessage);
                }
            }

            return(View(model));
        }
Пример #2
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                String        email  = User.Identity.Name;
                DBAccessor    dba    = new DBAccessor();
                LogonResponse result = dba.CheckLoginCredentials(email, model.OldPassword);

                if (result.success == (int)LogonResults.SUCCESS)
                {
                    if (dba.UpdateUserPassword(email, model.NewPassword))
                    {
                        return(RedirectToAction("ChangePasswordSuccess"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Password update failed, try again.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", result.errorMessage);
                }
            }
            return(View(model));
        }
Пример #3
0
        //
        // GET: /Account/Edit
        public ActionResult Edit()
        {
            String userEmail = User.Identity.Name;

            DBAccessor dba   = new DBAccessor();
            Person     user  = dba.GetPersonInformation(userEmail);
            EditModel  model = new EditModel();

            if (user != null)
            {
                model.FirstName = user.firstName;
                model.LastName  = user.lastName;
                model.Email     = user.email;
                model.Birthday  = user.birthday;
                model.Height    = Convert.ToInt16(user.height);
                model.Weight    = Convert.ToInt16(user.weight);
                model.ImageURL  = user.imageURL;
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
Пример #4
0
        public ActionResult GetInvalidRequests()
        {
            DBAccessor      dba      = new DBAccessor();
            List <LogEntry> messages = dba.GetLogMessages(LogType.INVALID_REQUEST);

            String result = "";

            if (messages != null)
            {
                if (messages.Count > 0)
                {
                    result  = "<table>";
                    result += "<tr><th>User</th><th>Message</th><th>Timestamp</th></tr>";
                    foreach (LogEntry message in messages)
                    {
                        string name = message.User.firstName + " " + message.User.lastName;
                        result += "<tr><td>" + name + "</td><td>" + message.Message + "</td><td>" + message.Timestamp + "</td></tr>";
                    }
                    result += "</table>";
                }
                else
                {
                    result = "There are no invalid requests logged at the moment.";
                }
            }
            else
            {
                result = "An error occured getting invalid requests.";
            }

            return(Json(
                       new { message = result },
                       JsonRequestBehavior.AllowGet
                       ));
        }
Пример #5
0
        public virtual string Remove()
        {
            DynamicJson dj         = GetParam();
            string      resJson    = string.Empty;
            string      primaryKey = "Id";

            try
            {
                JMI jmi = GetJMI(dj);
                using (DBAccessor dba = DBAccessor.Instance(Dbs.Get(jmi.DbsName)))
                {
                    string         condition = string.Empty;
                    string         sql       = string.Empty;
                    string         tableName = TableName(jmi.DtoType);
                    IList <string> cols      = new List <string>();

                    if (GetPrimaryKey(jmi.DtoType).Count() > 0)
                    {
                        primaryKey = GetPrimaryKey(jmi.DtoType).FirstOrDefault().Name;
                    }

                    DbParameter[] paras = BuildParameter(jmi.DtoType, dba, dj, ref cols);
                    int           rows  = dba.ExecuteCommand(string.Format("delete from {0} where {1}=:{1}", tableName, primaryKey), dba.CreateDbParameter(primaryKey, dj.Get(primaryKey)), false);
                    if (rows > 0)
                    {
                        resJson = new { result = 1 }
                    }
                    .ToJson();
                }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dJson"></param>
        /// <param name="dba"></param>
        /// <returns></returns>
        protected string OnSave(dynamic dJson, DBAccessor dba, bool isDelete = false)
        {
            string      json = string.Empty;
            DynamicJson dj   = dJson as DynamicJson;

            if (dj.IsList)
            {
                json = "[";
                int i = 0;
                foreach (DynamicJson djItem in dj)
                {
                    if (isDelete)
                    {
                        djItem.Set("IsDeleted", true);
                    }
                    json += DoSaveOne(dJson[i], dba) + ",";
                    i++;
                }
                json.TrimEnd(',');
                json += "]";
            }
            else if (dj.PropertyCount > 0)
            {
                if (isDelete)
                {
                    dj.Set("IsDeleted", true);
                }
                json = DoSaveOne(dj, dba);
            }
            return(json);
        }
Пример #7
0
        public DbCommand GetInsertCommand(object[] parameters)
        {
            if (TYPE != TableSchamaType.TABLE)
            {
                return(null);
            }
            if (_schama.Count <= 0)
            {
                return(null);
            }

            var sb_param   = new StringBuilder();
            var lst_params = new List <DbParameter>();
            var items      = _schama.OrderBy(itm => itm.ColumnOrdinal);

            foreach (var item in items)
            {
                if (item.ColumnOrdinal >= parameters.Length)
                {
                    break;
                }

                if (sb_param.Length > 0)
                {
                    sb_param.Append(",");
                }
                var parameter = DBAccessor.CreateParameter(string.Format("COL{0}", item.ColumnOrdinal), parameters[item.ColumnOrdinal]);
                sb_param.Append(parameter.ParameterName);
                lst_params.Add(parameter);
            }
            var sql = string.Format(SQL_INSERT_1, TableName, sb_param.ToString());

            return(DBAccessor.CreateCommand(sql, lst_params.ToArray()));
        }
Пример #8
0
        public ActionResult AccountSummary()
        {
            // Get the user information from the database
            DBAccessor dba  = new DBAccessor();
            Person     user = dba.GetPersonInformation(User.Identity.Name);

            String summaryMessage = "<h3>Account Summary</h3>";

            summaryMessage += "<p>" + user.firstName + " " + user.lastName + "</p>";
            summaryMessage += "<img src='" + user.imageURL + "' alt='profile image' />";
            summaryMessage += "</div>";

            List <Team> teamNames = dba.GetTeamListCoach(User.Identity.Name);

            summaryMessage += "<div id='sidebar-teamlist'><ul>";
            foreach (Team team in teamNames)
            {
                summaryMessage += "<li>" + team.name + "</li>";
            }
            summaryMessage += "</ul></div>";


            return(Json(
                       new { message = summaryMessage },
                       JsonRequestBehavior.AllowGet
                       ));
        }
Пример #9
0
        public void Test_GetPersonInformation_NotFound()
        {
            DBAccessor dba    = new DBAccessor();
            Person     person = dba.GetPersonInformation(TestConstants.GETPERSONINFORMATION_INVALIDEMAIL_ADMIN);

            Assert.AreEqual(null, person);
        }
Пример #10
0
        public ActionResult GetCoachRequests()
        {
            DBAccessor     dba      = new DBAccessor();
            List <Request> requests = dba.GetCoachRequests();

            String result = "";

            if (requests.Count > 0)
            {
                result  = "<table>";
                result += "<tr><th>Requestee</th><th>Email</th><th>Action</th></tr>";
                foreach (Request request in requests)
                {
                    string name = request.requestee.firstName + " " + request.requestee.lastName;
                    result += "<tr><td>" + name + "</td><td>" + request.requestee.email + "</td>";
                    result += "<td><img src='./../Content/images/accept.png' height='20' width='20' class='request-action-image' alt='accept' onClick='action_acceptcoachrequest(" + request.ID + ")' />";
                    result += "<img src='./../Content/images/decline.png' height='20' width='20' class='request-action-image' margin-right='5px' alt='decline' onClick='action_declinecoachrequest(" + request.ID + ")' /></td></tr>";
                }
                result += "</table>";
            }
            else
            {
                result = "There are no pending coach permission requests.";
            }

            return(Json(
                       new { message = result },
                       JsonRequestBehavior.AllowGet
                       ));
        }
Пример #11
0
        public void Test_CheckLoginCredentials_BadPassword()
        {
            DBAccessor    dba      = new DBAccessor();
            LogonResponse response = dba.CheckLoginCredentials(TestConstants.CHECKLOGINCREDENTIALS_VALIDEMAIL, TestConstants.CHECKLOGINCREDENTIALS_INVALIDPASS);

            Assert.AreEqual((int)LogonResults.PASSWORDMISMATCH, response.success);
        }
Пример #12
0
        private DataSet GetWordChunkDataSet(string word, string type)
        {
            var condition     = CreateCondition(word);
            var searchNum     = CreateType(type);
            var stringBuilder = new StringBuilder();

            //       stringBuilder.Append(
            //           @"select " + searchNum + @"VLevel,Word.ID as WordID,Word,Pronunciation,
            //               IMAGE.ImageID,IMAGE.Url,IMAGE.ThumnailUrl
            //            from [WordChunk].[dbo].[Rank] RANK
            //inner join  [WordChunk].[dbo].[WordChunk] WORD On WORD.ID = RANK.WordID
            //               inner join [WordChunk].[dbo].[Image] IMAGE On WORD.ID = IMAGE.WordID
            //               " + condition);

            //Sound.soundUrl,

            stringBuilder.Append(
                @"select " + searchNum + @"VLevel,Word.ID as WordID,Word,Pronunciation,
                    IMAGE.ImageID,IMAGE.Url,IMAGE.ThumnailUrl
	                from [WordChunk].[dbo].[Rank] RANK
					inner join  [WordChunk].[dbo].[WordChunk] WORD On WORD.ID = RANK.WordID
                    inner join [WordChunk].[dbo].[Image] IMAGE On WORD.ID = IMAGE.WordID
                    " + condition + "");

            return(DBAccessor.ExecuteSQLToGetDataBase(stringBuilder.ToString(), DataBaseType.WORD));
            //inner join[WordChunk].[dbo].[Sound]        Sound On WORD.ID = Sound.WordID
        }
Пример #13
0
        public void Test_CheckLoginCredentials_BadUsername()
        {
            DBAccessor    dba      = new DBAccessor();
            LogonResponse response = dba.CheckLoginCredentials(TestConstants.CHECKLOGINCREDENTIALS_INVALIDEMAIL, "Don't Care");

            Assert.AreEqual((int)LogonResults.USERNOTFOUND, response.success);
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dJson"></param>
        /// <param name="dba"></param>
        /// <returns></returns>
        protected virtual string DoSaveOne(DynamicJson dJson, DBAccessor dba)
        {
            string json = string.Empty;

            json = this.SaveOne(GetJMI(dJson).DtoType, dba, dJson);
            return(json);
        }
Пример #15
0
        public void Test_CheckEmail_NotFound()
        {
            DBAccessor dba       = new DBAccessor();
            bool       openEmail = dba.CheckEmail(TestConstants.CHECKEMAIL_OPENEMAIL);

            Assert.AreEqual(true, openEmail);
        }
Пример #16
0
 public virtual string Save()
 {
     try
     {
         DynamicJson dj  = GetParam();
         JMI         jmi = GetJMI(dj);
         if (!dj.IsList && !dj.GetStr(JModelNo.AccessSaveListKey).IsNullOrEmpty())
         {
             dj = dj.Get(JModelNo.AccessSaveListKey).ToJson().ToDynamicJson();
             if (!jmi.TBCode.IsNullOrWhiteSpace())
             {
                 foreach (DynamicJson djItem in dj)
                 {
                     djItem.Set(JModelNo.AccessTableKey, jmi.TBCode);
                 }
             }
         }
         using (DBAccessor dba = DBAccessor.Instance(Dbs.Get(jmi.DbsName)))
         {
             return(OnSave(dj, dba));
         }
     }
     catch (Exception ex)
     {
         return(Loger.Log(Assembly.GetExecutingAssembly().FullName, MethodBase.GetCurrentMethod().FullName(), ex));
     }
 }
Пример #17
0
        public void Test_CheckEmail_Found()
        {
            DBAccessor dba        = new DBAccessor();
            bool       takenEmail = dba.CheckEmail(TestConstants.CHECKEMAIL_TAKENEMAIL);

            Assert.AreEqual(false, takenEmail);
        }
        public override EtlStepResult Invoke(EtlContext context, IEtlLogger logger)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            if (this.Source == null)
            {
                throw new InvalidOperationException("Source cannot be null");
            }

            if (string.IsNullOrEmpty(this.Source.ConnectionString))
            {
                throw new InvalidOperationException("ConnectionString cannot be empty");
            }

            if (string.IsNullOrEmpty(this.Source.ProviderName))
            {
                throw new InvalidOperationException("ProviderName cannot be empty");
            }

            if (string.IsNullOrEmpty(this.Source.ProcedureName))
            {
                throw new InvalidOperationException("ProcedureName cannot be empty");
            }

            var result             = new EtlStepResult(EtlStatus.Succeeded, null);
            var hasOutputVariables = this.OutputVariables != null && this.OutputVariables.FirstRow.Count > 0;

            using (var dbAccessor = new DBAccessor(this.Source.ConnectionString, this.Source.ProviderName))
            {
                if (hasOutputVariables)
                {
                    using (var dbReader = dbAccessor.ExecuteProcedureReader(this.Source.ProcedureName, EtlProcedureParameter.ToDictionary(this.Source.Parameters), this.TimeoutMilliseconds))
                    {
                        if (dbReader.Read())
                        {
                            foreach (var firstRowResult in this.OutputVariables.FirstRow)
                            {
                                var firstRowResultValue = EtlValueTranslation.Evaluate(firstRowResult.SourceFieldName, firstRowResult.SourceFieldTranslation, dbReader, firstRowResult.DefaultValue);
                                result.VariableAssignments.Add(new EtlVariableAssignment(firstRowResult.VariableName, EtlValueConverter.ToString(firstRowResultValue)));
                            }
                        }
                    }
                }
                else
                {
                    dbAccessor.ExecuteProcedure(this.Source.ProcedureName, EtlProcedureParameter.ToDictionary(this.Source.Parameters), this.TimeoutMilliseconds);
                }
            }

            return(result);
        }
Пример #19
0
 public Faculty(string loginId)
 {
     InitializeComponent();
     LoginId   = loginId;
     DataSet   = new DataSet();
     accessor  = new DBAccessor();
     Connector = new DBConnector();
 }
Пример #20
0
        public void Test_CheckLoginCredentials_Valid()
        {
            DBAccessor    dba      = new DBAccessor();
            LogonResponse response = dba.CheckLoginCredentials(TestConstants.CHECKLOGINCREDENTIALS_VALIDEMAIL, TestConstants.CHECKLOGINCREDENTIALS_VALIDPASS);

            Assert.AreEqual((int)LogonResults.SUCCESS, response.success);
            Assert.AreEqual(TestConstants.CHECKLOGINCREDENTIALS_VALIDEMAIL, response.user.email);
            Assert.AreEqual(TestConstants.CHECKLOGINCREDENTIALS_FIRSTNAME, response.user.firstName);
            Assert.AreEqual(TestConstants.CHECKLOGINCREDENTIALS_LASTNAME, response.user.lastName);
        }
Пример #21
0
        public void RetrieveReader(Action <DbDataReader> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("parameter(action) is null!", "action");
            }
            var command = GetSelectCommand();

            DBAccessor.RetrieveReader(command, action);
        }
Пример #22
0
 public string DoDelete(Type dtotype, DBAccessor dba, DynamicJson dj)
 {
     try
     {
         return(SaveOne(dtotype, dba, dj));
     }
     catch (Exception ex)
     {
         return(Loger.Log(Assembly.GetExecutingAssembly().FullName, MethodBase.GetCurrentMethod().FullName(), ex));
     }
 }
Пример #23
0
        public long TruncateTable()
        {
            long rows = 0;

            if (TYPE == TableSchamaType.TABLE && Exists)
            {
                var command = GetTruncateCommand();
                rows = DBAccessor.ExecuteSQLCommand(command);
            }
            return(rows);
        }
Пример #24
0
        public ActionResult AddCoachRequest()
        {
            String     result = "Coach permission has been requested.";
            DBAccessor dba    = new DBAccessor();

            // Add request to the DB
            string email     = User.Identity.Name;
            Person requestee = dba.GetPersonInformation(email);

            if (requestee != null)
            {
                if (dba.AddNewRequest(requestee.ID, RequestType.COACH_PERMISSION))
                {
                    // Send email that a request was added
                    try {
                        // Form an email
                        MailMessage newMessage  = new MailMessage();
                        SmtpClient  mailService = new SmtpClient();

                        //set the addresses
                        newMessage.From = new MailAddress(AppConstants.EMAIL_ADMIN);
                        newMessage.To.Add(AppConstants.EMAIL_ADMIN);

                        //set the content
                        newMessage.Subject = "Coach Permission Requested";
                        newMessage.Body    = requestee.firstName + " " + requestee.lastName + " has requested coach access (email: " + requestee.email + ").";

                        //send the message
                        mailService.UseDefaultCredentials = false;
                        mailService.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        mailService.Host        = AppConstants.EMAIL_SMTP_ADDRESS;
                        mailService.Credentials = new NetworkCredential(AppConstants.EMAIL_SMTP_USERNAME, AppConstants.EMAIL_SMTP_PASSWORD);
                        mailService.Send(newMessage);
                    }
                    catch (Exception) {
                        result = "Error notifying the site administrator.";
                    }
                }
                else
                {
                    result = "Couldn't add a request to the database.";
                }
            }
            else
            {
                result = "Couldn't find the user in the database.";
            }

            return(Json(
                       new { message = result },
                       JsonRequestBehavior.AllowGet
                       ));
        }
Пример #25
0
        private DataSet GetAnalyticDataSet(string word)
        {
            var condition     = CreateCondition(word);
            var stringBuilder = new StringBuilder();

            stringBuilder.Append(
                @"select top 10 WORD.ID as WordID,WORD.word,A.ID as ArticleID,A.Title,A.Intro,A.Contents,A.Url,A.ThumnailUrl,A.Time
                            from [WordChunk].[dbo].[WordChunk] WORD
	                        left outer join [WordChunk].[dbo].[ArticleWordRelation] R On WORD.ID = R.WordID
                            left outer join [WordChunk].[dbo].[ArticleContents] A On R.ArticleID = A.ID
	                        where WORD.ID = "     + word);
            return(DBAccessor.ExecuteSQLToGetDataBase(stringBuilder.ToString(), DataBaseType.WORD));
        }
Пример #26
0
        public void Test_GetPersonInformation_Found_SiteAdmin()
        {
            DBAccessor dba    = new DBAccessor();
            Person     person = dba.GetPersonInformation(TestConstants.GETPERSONINFORMATION_VALIDEMAIL_ADMIN);

            Assert.AreEqual(TestConstants.GETPERSONINFORMATION_VALIDEMAIL_ADMIN, person.email);
            Assert.AreEqual(TestConstants.GETPERSONINFORMATION_PASSWORD_ADMIN, person.getUnencryptedPassword());
            Assert.AreEqual(TestConstants.GETPERSONINFORMATION_FIRSTNAME_ADMIN, person.firstName);
            Assert.AreEqual(TestConstants.GETPERSONINFORMATION_LASTNAME_ADMIN, person.lastName);
            Assert.AreEqual(TestConstants.GETPERSONINFORMATION_USERID_ADMIN, person.ID);
            Assert.AreEqual(TestConstants.GETPERSONINFORMATION_COACHENABLED_ADMIN, person.permissions.coachEnabled);
            Assert.AreEqual(TestConstants.GETPERSONINFORMATION_SITEADMIN_ADMIN, person.permissions.siteAdmin);
        }
Пример #27
0
        public bool AddProductType(string typeName, int parentID)
        {
            int id = DBAccessor.AddProductType(typeName, parentID);

            if (id == -1)
            {
                return(false);
            }
            ProductType type = new ProductType(id, typeName, parentID);

            productTypeList.AddType(type);
            return(true);
        }
Пример #28
0
        public CustomerSegmentation(string Loginid)
        {
            Accessor = new DBAccessor();

            LoginID = Loginid;

            Connector = new DBConnector(LoginID, 1);

            DataSet = new DataSet();

            InitializeComponent();

            AppLoad();
        }
Пример #29
0
        public ActionResult AcceptCoachRequest(long requestID)
        {
            String     result  = "Coach permission added.";
            DBAccessor dba     = new DBAccessor();
            Request    request = dba.GetRequest(requestID, RequestType.COACH_PERMISSION);

            if (request != null)
            {
                if (dba.AddCoachPermission(request.requestee.ID))
                {
                    // Form an email
                    MailMessage newMessage  = new MailMessage();
                    SmtpClient  mailService = new SmtpClient();

                    //set the addresses
                    newMessage.From = new MailAddress(AppConstants.EMAIL_ADMIN);
                    newMessage.To.Add(request.requestee.email);

                    //set the content
                    newMessage.Subject = "Coach Permission Approved";
                    newMessage.Body    = "Your request to receive coach permission at dugoutdigits.com has been approved.";

                    //send the message
                    mailService.UseDefaultCredentials = false;
                    mailService.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    mailService.Host        = AppConstants.EMAIL_SMTP_ADDRESS;
                    mailService.Credentials = new NetworkCredential(AppConstants.EMAIL_SMTP_USERNAME, AppConstants.EMAIL_SMTP_PASSWORD);
                    mailService.Send(newMessage);

                    // Remove the request from the DB
                    if (!dba.RemoveRequest(request.ID))
                    {
                        result = "Error removing the coach request from the database (ID=" + request.ID + ").";
                    }
                }
                else
                {
                    result = "Error adding coach permission.";
                }
            }
            else
            {
                result = "The request couldn't be found in the database.";
            }

            return(Json(
                       new { message = result },
                       JsonRequestBehavior.AllowGet
                       ));
        }
Пример #30
0
        private void RegisterSearchWord(string word, DataSet dataset, HttpRequestMessage Request, Stopwatch sw)
        {
            if (word != "")
            {
                var stringBuilder = new StringBuilder();

                var ipAddress = Utility.GetClientIpAddress(Request);

                var resultNum = dataset.Tables[0].Rows.Count;

                stringBuilder.Append("insert into [dbo].[Search] (SearchWord,IPAddress,ResultNum,SearchTime,Time) values");
                stringBuilder.Append("('" + word.Replace("'", "''") + "','" + ipAddress + "','" + resultNum + "','" + sw.ElapsedMilliseconds + "','" + Utility.GetDateTimeNow() + "');");

                DBAccessor.ExecuteSQLScalar(stringBuilder.ToString(), DataBaseType.WORD);
            }
        }