public List<EmploymentDTO> findAll()
    {
        var objs = (from p in ctx.Employments
                    select p);
        EmploymentDTO add = null;
        List<EmploymentDTO> addList = new List<EmploymentDTO>();
        foreach (Employment obj in objs)
        {
            add = new EmploymentDTO();
            add.userName = obj.userName;
            add.startDate = obj.startDate;
            add.title = obj.title;
            add.company = obj.company;
            add.industry = obj.industry;
            add.town = obj.town;
            add.province = obj.province;
            add.country = obj.country;
            add.empType = obj.empType;
            add.currentEmployer = obj.currentEmployer;
            add.gross = Double.Parse(obj.gross.ToString());
            add.startDate = obj.startDate;
            add.endDate = obj.endDate;
            add.responsibilities = obj.responsibilities;

            addList.Add(add);
        }
        return addList;
    }
Beispiel #2
0
        //[Authorize(Roles = "SuperUser")]
        public async Task <ActionResult <EmploymentDTO> > EmployUser(EmploymentDTO employmentDTO)
        {
            //Use Identity Role to check if logged user is a superuser
            //Can wire up the AUTHORIZE attribute or custom check using the HttpClient object
            //if (currentUser.Role != superUser)
            //{
            //    _logger.LogWarning("Hack Attempt");
            //    return BadRequest();
            //}

            var employment = new Employment
            {
                UserId         = employmentDTO.UserId,
                EmployerId     = employmentDTO.EmployerId,
                IsSuperUser    = employmentDTO.IsSuperUser,
                AssignmentDate = DateTime.UtcNow
            };

            try
            {
                _context.Employments.Add(employment);
                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                _logger.LogError("Error occurred while Employing a User");
                throw;
            }

            return(CreatedAtAction("EmployUser", new { id = employment.Id }, ConvertEmployment(employment)));
        }
    public EmploymentDTO find(string userName, DateTime startDate)
    {
        EmploymentDTO info = new EmploymentDTO();
        SqlConnection oConn = new SqlConnection();
        SqlCommand sqlCmd = null;

        try
        {
            oConn.ConnectionString = ConfigurationManager.AppSettings["conn"];
            oConn.Open();

            sqlCmd = oConn.CreateCommand();
            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.CommandText = "select * from Employment where userName = '******' AND startDate = '" + startDate + "'";

            SqlDataReader rdr = sqlCmd.ExecuteReader();

            if (rdr.HasRows)
            {
                while (rdr.Read())
                {

                    info.userName = rdr["userName"].ToString();
                    info.title = rdr["title"].ToString();
                    info.company = rdr["company"].ToString();
                    info.industry = rdr["industry"].ToString();
                    info.town = rdr["town"].ToString();
                    info.province = rdr["province"].ToString();
                    info.country = rdr["country"].ToString();
                    info.empType = rdr["empType"].ToString();
                    info.currentEmployer = rdr["currentEmployer"].ToString();
                    info.gross = Double .Parse(rdr["gross"].ToString() );
                    info.startDate = DateTime.Parse( rdr["startDate"].ToString() );
                    info.endDate = DateTime.Parse(rdr["endDate"].ToString() );
                    info.responsibilities = rdr["responsibilities"].ToString();
                }
            }

        }
        catch
        { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return info;
    }
        public void EmploymentDAO_Test()
        {
            /*Context*/
            EmploymentDAO emp_context = new EmploymentDAO();
            AccountDAO account_context = new AccountDAO();

            /*Insert*/
            AccountDTO account = new AccountDTO();
            account.userName = "******";
            account.status = "active";
            account.password = "******";
            account.accountType = "admin";

            account_context.presist(account);

            EmploymentDTO employment = new EmploymentDTO();
            employment.company = "fuzion";
            employment.country = "SA";
            employment.currentEmployer = "Apple";
            employment.empType = "Contract";
            employment.endDate = new DateTime(2012, 12, 30);
            employment.gross = 10000;
            employment.industry = "IT";
            employment.province = "WP";
            employment.responsibilities = "web development";
            employment.startDate = new DateTime(2012, 6, 7);
            employment.title = "web developer";
            employment.town = "cape town";
            employment.userName = "******";

            emp_context.presist(employment);

            bool expected = true;
            bool actual;
            actual = emp_context.isFound("griddy", new DateTime(2012, 6, 7) );
            Assert.AreEqual(expected, actual);

            /*Update*/
            employment.gross = 125000;
            emp_context.merge(employment);

            double expectedUpdate = 125000;
            EmploymentDTO contUpd = emp_context.find("griddy", new DateTime(2012, 6, 7));
            Assert.AreEqual(expectedUpdate, contUpd.gross);

            /*Delete*/
            emp_context.removeByUserId("griddy", new DateTime(2012, 6, 7));
            bool expectedDelete = false;
            bool actualDelete = emp_context.isFound("griddy", new DateTime(2012, 6, 7));
            Assert.AreEqual(expectedDelete, actualDelete);

            account_context.removeByUserId("griddy");
        }
    public EmploymentDTO find(string userName, DateTime startDate)
    {
        var obj = (from p in ctx.Employments
                   where p.userName == @userName && p.startDate == @startDate
                   select p).Single();

        EmploymentDTO add = new EmploymentDTO();
        add.userName = obj.userName;
        add.title = obj.title;
        add.company = obj.company;
        add.industry = obj.industry;
        add.town = obj.town;
        add.province = obj.province;
        add.country = obj.country;
        add.empType = obj.empType;
        add.currentEmployer = obj.currentEmployer;
        add.gross = Double.Parse(obj.gross.ToString() );
        add.startDate = obj.startDate;
        add.endDate = obj.endDate;
        add.responsibilities = obj.responsibilities;

        return add;
    }
 public void setEmploymentDto(EmploymentDTO employmentDto)
 {
     view.setTitle(employmentDto.title);
     view.setCompany(employmentDto.company);
     view.setIndustry(employmentDto.industry);
     view.setTown(employmentDto.town);
     view.setProvince(employmentDto.province);
     view.setCountry(employmentDto.country);
     view.setEducationType(employmentDto.empType);
     view.setCurrentEmployer(employmentDto.currentEmployer);
     view.setGross(employmentDto.gross.ToString());
     view.setStartDate(employmentDto.startDate.ToString());
     view.setEndDate(employmentDto.endDate.ToString());
     view.setResponsibilities(employmentDto.responsibilities);
     //view.setUsername(employmentInformationDto.userName);
 }
 public EmploymentDTO getEmploymentDto()
 {
     EmploymentDTO employmentDto = new EmploymentDTO();
     employmentDto.userName = view.getUsername();
     employmentDto.country = view.getCountry();
     employmentDto.company = view.getCompany();
     employmentDto.currentEmployer = view.getCurrentEmployer();
     employmentDto.empType = view.getEducationType();
     employmentDto.endDate = view.getEndDate();
     employmentDto.gross = view.getGross();
     employmentDto.industry = view.getIndustry();
     employmentDto.province = view.getProvince();
     employmentDto.responsibilities = view.getResponsibilities();
     employmentDto.startDate = view.getStartDate();
     employmentDto.title = view.getTitle();
     employmentDto.town = view.getTown();
     return employmentDto;
 }
 public bool remove(EmploymentDTO entity)
 {
     return this.removeByUserId(entity.userName, entity.startDate);
 }
    public bool presist(EmploymentDTO entity)
    {
        bool success = false;
        SqlConnection oConn = new SqlConnection();
        SqlCommand sqlCmd = null;

        try
        {
            oConn.ConnectionString = ConfigurationManager.AppSettings["conn"];
            oConn.Open();

            sqlCmd = oConn.CreateCommand();
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "insertEmployment";
            sqlCmd.Parameters.Add(new SqlParameter("userName", entity.userName));
            sqlCmd.Parameters.Add(new SqlParameter("title", entity.title));
            sqlCmd.Parameters.Add(new SqlParameter("company", entity.company));
            sqlCmd.Parameters.Add(new SqlParameter("industry", entity.industry));
            sqlCmd.Parameters.Add(new SqlParameter("town", entity.town));
            sqlCmd.Parameters.Add(new SqlParameter("province", entity.province));
            sqlCmd.Parameters.Add(new SqlParameter("country", entity.country));
            sqlCmd.Parameters.Add(new SqlParameter("empType", entity.empType));
            sqlCmd.Parameters.Add(new SqlParameter("currentEmployer", entity.currentEmployer));
            sqlCmd.Parameters.Add(new SqlParameter("gross", entity.gross));
            sqlCmd.Parameters.Add(new SqlParameter("startDate", entity.startDate));
            sqlCmd.Parameters.Add(new SqlParameter("endDate", entity.endDate));
            sqlCmd.Parameters.Add(new SqlParameter("responsibilities", entity.responsibilities));

            SqlDataReader rdr = sqlCmd.ExecuteReader();
            if (rdr.HasRows)
            {
                while (rdr.Read())
                { } //Read all
            }
            rdr.Close();

            if (rdr.RecordsAffected > 0)
                success = true;
        }
        catch { }
        finally
        {
            if (sqlCmd != null)
            {
                sqlCmd = null;
            }
            if (oConn != null)
            {
                if (oConn.State.Equals(ConnectionState.Open))
                {
                    oConn.Close();
                }
                oConn = null;
            }
        }
        return success;
    }
    public bool merge(EmploymentDTO entity)
    {
        try
        {
            var addObj = (from p in ctx.Employments
                       where p.userName == @entity.userName && p.startDate == @entity.startDate
                       select p).Single();

            model.Employment obj = (Employment)addObj;

            /*Update*/
            obj.userName = entity.userName;
            obj.startDate = entity.startDate;
            obj.title = entity.title;
            obj.company = entity.company;
            obj.industry = entity.industry;
            obj.town = entity.town;
            obj.province = entity.province;
            obj.country = entity.country;
            obj.empType = entity.empType;
            obj.currentEmployer = entity.currentEmployer;
            obj.gross = Decimal.Parse(entity.gross.ToString());
            obj.startDate = entity.startDate;
            obj.endDate = entity.endDate;
            obj.responsibilities = entity.responsibilities;

            ctx.SubmitChanges();
            return true;
        }
        catch (Exception e)
        {
            model.Log log = new Log();
            log.message = "Employment Merge: " + " ["+entity.userName+" , "+entity.startDate+"] " + e.Message;
            ctx.SubmitChanges();

            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }
    public bool presist(EmploymentDTO entity)
    {
        try
        {
            model.Employment obj = new Employment();
            obj.userName = entity.userName;
            obj.startDate = entity.startDate;
            obj.title = entity.title;
            obj.company = entity.company;
            obj.industry = entity.industry;
            obj.town = entity.town;
            obj.province = entity.province;
            obj.country = entity.country;
            obj.empType = entity.empType;
            obj.currentEmployer = entity.currentEmployer;
            obj.gross = Decimal.Parse(entity.gross.ToString() );
            obj.startDate = entity.startDate;
            obj.endDate = entity.endDate;
            obj.responsibilities = entity.responsibilities;

            ctx.Employments.InsertOnSubmit(obj);
            ctx.SubmitChanges();
            return true;
        }
        catch (Exception)
        {
            ctx.Dispose();
            ctx = new ModelDataContext();
            return false;
        }
    }