private static Project GetProject(object project)
        {
            var objProject = new Project();
            var tmp = (Dictionary<string, object>)project;

            object objId = null;
            object objName = null;
            object objDescription = null;
            object objStartDate = null;
            object objEndDate = null;
            object objIsActive = null;

            if (tmp.TryGetValue("Id", out objId))
                objProject.Id = string.IsNullOrEmpty(objId.ToString()) ? 0 : int.Parse(objId.ToString());

            if (tmp.TryGetValue("Name", out objName))
                objProject.Name = objName.ToString();

            if (tmp.TryGetValue("Description", out objDescription))
                objProject.Description = objDescription.ToString();

            if (tmp.TryGetValue("StartDate", out objStartDate))
                objProject.StartDate = DateTime.Parse(objStartDate.ToString());

            if (tmp.TryGetValue("EndDate", out objEndDate))
                objProject.EndDate = DateTime.Parse(objEndDate.ToString());

            if (tmp.TryGetValue("IsActive", out objIsActive))
                objProject.IsActive = bool.Parse(objIsActive.ToString());

            return objProject;
        }
        public static void Add(Project project)
        {
            if(project.Id> 0 )
            {
                        //Edit
                EditProject(project);

            }
            else
            {
                 //add
                AddProject(project);
            }

            //if (ProjectData.ContainsKey(project.Id))
            //{
            //    //edit
            //    ProjectData[project.Id] = project;
            //}
            //else
            //{
            //    //add
            //    project.Id = _idCounter++;
            //    ProjectData.Add(project.Id, project);
            //}
        }
 /// <summary>
 /// get allocated project list for a specific user
 /// </summary>
 /// <param name="dbUserId"></param>
 /// <returns></returns>
 public static IEnumerable<Project> GetUserProjects(int dbUserId)
 {
     SqlConnection con = new SqlConnection(SqlConString);
     List<Project> projects = new List<Project>();
     try
     {
         string strquery = "select p.Id_Project,p.ProjectName from DTSUserProject up inner join DTSProject p on up.ProjectId = p.Id_Project"+
                             " where up.UserId =" + dbUserId;
         SqlCommand cmd = new SqlCommand(strquery, con);
         con.Open();
         SqlDataReader reader = cmd.ExecuteReader();
         if (reader != null)
         {
             while (reader.Read())
             {
                 var project = new Project();
                 project.Id = int.Parse(reader["Id_Project"].ToString());
                 project.Name = reader["ProjectName"].ToString();
                 project.Description = reader["ProjectName"].ToString();
                 projects.Add(project);
             }
         }
         reader.Close();
     }
     catch (Exception ex)
     {
         throw (ex);
     }
     finally
     {
         if (con != null) con.Close();
     }
     return projects;
 }
        private static void EditProject(Project project)
        {
            SqlConnection conn = new SqlConnection(SqlConString);

            //Create the SqlCommand object
            SqlCommand cmd = new SqlCommand("sp_addeditdeleteProject", conn);
            //Specify that the SqlCommand is a stored procedure
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            //Add the input parameters to the command object
            cmd.Parameters.AddWithValue("@Proj_Id", project.Id);
            cmd.Parameters.AddWithValue("@ProjName", project.Name);
            cmd.Parameters.AddWithValue("@ProjDesc", project.Description);
            cmd.Parameters.AddWithValue("@IsActive", project.IsActive);
            cmd.Parameters.AddWithValue("@ModifyDate", project.EndDate);
            cmd.Parameters.AddWithValue("@StatementType", "Update");
            //cmd.Parameters.Add(new SqlParameter("Id", project.Id));

            //Open the connection and execute the query
            conn.Open();
            cmd.ExecuteNonQuery();
        }
 public static IEnumerable<Project> GetProjectsForAssignment()
 {
     SqlConnection con = new SqlConnection(SqlConString);
     List<Project> lst = new List<Project>();
     try
     {
         string strquery = "Select * from DTSProject";
         SqlCommand cmd = new SqlCommand(strquery, con);
         con.Open();
         SqlDataReader reader = cmd.ExecuteReader();
         if (reader != null)
         {
             while (reader.Read())
             {
                 Project p = new Project();
                 p.Id = int.Parse(reader[0].ToString());
                 p.Name = reader[1].ToString();
                 //p.StartDate = Convert.ToDateTime(reader[2].ToString());
                 //p.EndDate = Convert.ToDateTime(reader[3].ToString());
                 p.Description = reader[4].ToString();
                 //p.IsActive = Convert.ToBoolean(reader[5].ToString());
                 lst.Add(p);
             }
         }
         reader.Close();
     }
     catch (Exception ex)
     {
         throw (ex);
     }
     finally
     {
         if (con != null) con.Close();
     }
     return lst;
 }