/// <summary> /// Execution of the Command /// </summary> /// <param name="param">Id</param> /// <returns>User</returns> public override Entity Execute(string param) { string strClass = "CommandGetUser"; Entity user = FactoryEntity.GetUser(); try { IDaoUser daoUser = FactoryDao.GetDaoUser(); DataSet dsUser = daoUser.GetById(param); Command <DataSet, List <Entity> > commandConvertToJSON = FactoryCommand.GetCommandConvertUserIntoJSON(); user = commandConvertToJSON.Execute(dsUser)[0]; } catch (Exception e) { IDaoUser daoUser = FactoryDao.GetDaoUser(); daoUser.CreateLog(strClass, "There was a problem exectuting the command to get one user", true); throw new Exception("There was a problem exectuting the command to get one user", e); } return(user); }
/// <summary> /// Execution of the Command /// </summary> /// <param name="param">DataSet from DB</param> /// <returns>List of Users</returns> public override List <Entity> Execute(DataSet param) { string strClass = "CommandConvertUserIntoJSON"; List <Entity> list = new List <Entity>(); int result; DateTime resultDT; try { if (param != null) { foreach (DataRow dr in param.Tables["DATA"].Rows) { Entity user = FactoryEntity.GetUser(); ((User)user).Id = (dr["USER_ID"] != null && !String.IsNullOrEmpty(dr["USER_ID"].ToString())) ? (int.TryParse(dr["USER_ID"].ToString(), out result) ? int.Parse(dr["USER_ID"].ToString()) : -1) : -1; ((User)user).Name = (dr["USER_NAME"] != null && !String.IsNullOrEmpty(dr["USER_NAME"].ToString())) ? dr["USER_NAME"].ToString() : ""; ((User)user).Birthdate = (dr["USER_BIRTHDATE"] != null && !String.IsNullOrEmpty(dr["USER_BIRTHDATE"].ToString())) ? (DateTime.TryParse(dr["USER_BIRTHDATE"].ToString(), out resultDT) ? DateTime.Parse(dr["USER_BIRTHDATE"].ToString()).Month.ToString() + "-" + DateTime.Parse(dr["USER_BIRTHDATE"].ToString()).Day.ToString() + "-" + DateTime.Parse(dr["USER_BIRTHDATE"].ToString()).Year.ToString() : "") : ""; list.Add(user); } } } catch (Exception e) { IDaoUser daoUser = FactoryDao.GetDaoUser(); daoUser.CreateLog(strClass, "There was a problem converting the user into a JSON", true); throw new Exception("There was a problem converting the user into a JSON", e); } return(list); }