Пример #1
0
 public ActionResult Add()
 {
     var goal = new Goal();
     ViewBag.ActionName = "Add";
     ViewBag.Title = "Add a Goal";
     return View("EditGoal", goal);
 }
Пример #2
0
 public void Delete(Goal goal)
 {
     using (DbCommand cmd = _db.GetSqlStringCommand(GoalQueries.DeleteGoal))
     {
         _db.AddInParameter(cmd, "@GoalID", DbType.Int32, goal.Id);
         _db.AddInParameter(cmd, "@UpdatedBy", DbType.Int32, goal.UpdatedBy);
         _db.ExecuteNonQuery(cmd);
     }
 }
Пример #3
0
        public Goal Add(Goal goal)
        {
            using (DbCommand cmd = _db.GetSqlStringCommand(GoalQueries.AddGoal))
            {
                _db.AddInParameter(cmd, "@Name", DbType.String, goal.Name);
                _db.AddInParameter(cmd, "@SystemName", DbType.String, goal.SystemName);
                _db.AddInParameter(cmd, "@Value", DbType.Double, goal.Value);
                _db.AddInParameter(cmd, "@GACode", DbType.String, goal.GACode);
                _db.AddInParameter(cmd, "@CustomJS", DbType.String, goal.CustomJS);
                _db.AddInParameter(cmd, "@CreatedBy", DbType.String, goal.CreatedBy);

                using (IDataReader reader = _db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        return ReaderToGoal(reader);
                    }
                }
            }

            return goal;
        }
Пример #4
0
        public ActionResult Update(Goal goal)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    goal.UpdatedBy = HttpContext.User.Identity.Name;
                    goal = goalRepository.Update(goal);
                    return Redirect("/Goals/");
                }
                else
                {
                    ViewBag.ErrorMessage = "There is a problem with one of your response.";
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "An Error Occurred while attempting to save that goal.";
            }

            ViewBag.ActionName = "Update";
            ViewBag.Title = "Edit Goal";
            return View("EditGoal", goal);
        }
Пример #5
0
        protected Goal ReaderToGoal(IDataReader reader)
        {
            var goal = new Goal();

            if (reader["Id"] != DBNull.Value)
            {
                goal.Id = Convert.ToInt32(reader["Id"]);
            }

            if (reader["Name"] != DBNull.Value)
            {
                goal.Name = reader["Name"].ToString();
            }

            if (reader["SystemName"] != DBNull.Value)
            {
                goal.SystemName = reader["SystemName"].ToString();
            }

            if (reader["Value"] != DBNull.Value)
            {
                goal.Value = Convert.ToDouble(reader["Value"]);
            }

            if (reader["GACode"] != DBNull.Value)
            {
                goal.GACode = reader["GACode"].ToString();
            }

            if (reader["CustomJS"] != DBNull.Value)
            {
                goal.CustomJS = reader["CustomJS"].ToString();
            }

            if (reader["CreatedBy"] != DBNull.Value)
            {
                goal.CreatedBy = reader["CreatedBy"].ToString();
            }

            if (reader["UpdatedBy"] != DBNull.Value)
            {
                goal.UpdatedBy = reader["UpdatedBy"].ToString();
            }

            if (reader["Created"] != DBNull.Value)
            {
                goal.Created = Convert.ToDateTime(reader["Created"]);
            }

            if (reader["Updated"] != DBNull.Value)
            {
                goal.Updated = Convert.ToDateTime(reader["Updated"]);
            }

            return goal;
        }
Пример #6
0
        public Goal Update(Goal goal)
        {
            using (DbCommand cmd = _db.GetSqlStringCommand(GoalQueries.UpdateGoal))
            {
                _db.AddInParameter(cmd, "@Name", DbType.String, goal.Name);
                _db.AddInParameter(cmd, "@Value", DbType.Double, goal.Value);
                _db.AddInParameter(cmd, "@GACode", DbType.String, goal.GACode);
                _db.AddInParameter(cmd, "@CustomJS", DbType.String, goal.CustomJS);
                _db.AddInParameter(cmd, "@UpdatedBy", DbType.String, goal.UpdatedBy);
                _db.AddInParameter(cmd, "@GoalID", DbType.Int32, goal.Id);

                _db.ExecuteNonQuery(cmd);
            }

            return goal;
        }