예제 #1
0
    /// <summary>
    /// This function add Client Contacts to group
    /// </summary>
    /// <param name="gr"></param>   
    /// <returns></returns>
    public int AddClientContactsToGroup(ClientContactAddToGroup gr)
    {
        var context = new dbDataContext();
        // check for the group
        if (gr.Group.GroupId == 0 && !string.IsNullOrEmpty(gr.Group.Name.Trim()))
        {
            //create new group
            var group = new tbl_Group
             {
                 UserId = gr.Group.UserId,
                 CreatedDate = DateTime.Now,
                 IsPublic = gr.Group.IsPublic,
                 Name = gr.Group.Name.Trim()
             };
            context.tbl_Groups.InsertOnSubmit(group);
            context.SubmitChanges();
            gr.Group.GroupId = group.GroupId;
        }
        else if (gr.Group.GroupId == 0)
            return -1;

        //add client and contacts 
        if (!string.IsNullOrEmpty(gr.SelectedIds))
        {
            //If selected Ids were passed
            foreach (var id in gr.SelectedIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
            {
                var contactId = int.Parse(id);
                var contactCount =
                    context.tbl_CandidateGroups.Count(t => t.GroupId == gr.Group.GroupId && t.CandidateId == contactId);
                if (contactCount == 0)
                {
                    var clientContactGroup = new tbl_CandidateGroup
                    {
                        CandidateId = contactId,
                        GroupId = gr.Group.GroupId
                    };
                    context.tbl_CandidateGroups.InsertOnSubmit(clientContactGroup);
                    context.SubmitChanges();
                }
            } 
        }
        else
        {
            //use stored procedure to insert contacts/clients
            var filters = gr.Filter;
            // setup the parameters
            SqlParameter[] parameters = {
	                       new SqlParameter("@GroupToAdd", gr.Group.GroupId), 
                           new SqlParameter("@ConsultantId", filters.ConsultantId),
                           new SqlParameter("@UserId", filters.UserId),
                           new SqlParameter("@ClientId", filters.ClientId ),
                           new SqlParameter("@ContactStatuses", filters.ContactStatusIds),
                           new SqlParameter("@ClientStatuses", filters.ClientStatusIds),
                           new SqlParameter("@Client", filters.Client),
                           new SqlParameter("@Forename", filters.Forename),
                           new SqlParameter("@Surname", filters.Surname),
                           new SqlParameter("@Email", filters.Email),
                           new SqlParameter("@JobTitle", filters.JobTitle),   
                           new SqlParameter("@Employer", filters.Employer),
	                       new SqlParameter("@Sectors", filters.Sectors),
	                       new SqlParameter("@Locations", filters.Locations), 
                           new SqlParameter("@Qualifications", filters.Qualifications),
	                       new SqlParameter("@Skills", filters.Skills),
	                       new SqlParameter("@MinSalary", filters.MinSalary),
	                       new SqlParameter("@MaxSalary", filters.MaxSalary),
	                       new SqlParameter("@Keyword", filters.Keyword),
	                       new SqlParameter("@SortBy", filters.SortBy), 
	                       new SqlParameter("@Deleted" ,filters.Deleted),	
	                       new SqlParameter("@LastUpdatedDateFrom" ,filters.LastUpdatedDateFrom),
	                       new SqlParameter("@LastUpdatedDateTo", filters.LastUpdatedDateTo),
	                       new SqlParameter("@VacancyType" ,filters.VacancyType),
                           new SqlParameter("@Hours" ,filters.Hours), 
                           new SqlParameter("@GroupId" ,filters.GroupId),
                           new SqlParameter("@LocationRadius" ,filters.LocationRadius),
	                       new SqlParameter("@RetrieveType",filters.RetrieveType)
            };
            // setup the connection
            var conn = new Sql_DataAccess(_connString);
            //execute th stored procedure
            conn.GetDataSetFromSP("AddClientsContactsToGroupsByFilter", parameters); 
        } 
        return gr.Group.GroupId;
    }
예제 #2
0
 public int AddClientContactsForGroup(ClientContactAddToGroup data)
 {
     return new CandidateGroups().AddClientContactsToGroup(data);
 }