public bool SaveSkills(TechnologiesAndSkills skill) { try { var existingCount = this.TechnologiesAndSkills.Count(a => a.TechnologyAndSkillID.Equals(skill.TechnologyAndSkillID)); if (existingCount == 0) { // insert user skill.Active = true; TechnologiesAndSkills.Add(skill); } else { TechnologiesAndSkills u = this.TechnologiesAndSkills.Where(s => s.TechnologyAndSkillID == skill.TechnologyAndSkillID).FirstOrDefault <TechnologiesAndSkills>(); // change contact in disconnected mode (out of DBContext scope) if (u != null) { u.CompanyID = skill.CompanyID; u.Code = skill.Code; u.Name = skill.Name; u.SkillType = skill.SkillType; u.Active = true; } this.Entry(u).State = EntityState.Modified; } this.SaveChanges(); return(true); } catch { throw; } }
public int SaveIndent(Indent indent) { try { // add into technologies if not found int compid = (from t in this.Departments where t.DepartmentID == indent.DepartmentID select t.CompanyID).FirstOrDefault(); if (indent.Technologies != null) { string[] techs = indent.Technologies.Split(';'); if (techs.Length > 0) { foreach (string tech in techs) { if (!string.IsNullOrWhiteSpace(tech)) { string t = tech.Trim(); var cnt = this.TechnologiesAndSkills.Count(a => a.Code.Trim().Equals(t)); if (cnt == 0) { TechnologiesAndSkills a = new Entity.TechnologiesAndSkills() { Code = t, Name = t, Active = true, CompanyID = compid, SkillType = 1 }; TechnologiesAndSkills.Add(a); } } } } } // add/update indent var count = this.Indents.Count(a => a.IndentID.Equals(indent.IndentID)); if (count == 0) { var code = (from t in this.Departments join c in this.Company on t.CompanyID equals c.CompanyID where t.DepartmentID == indent.DepartmentID select new { CompanyCode = c.Code, DepartmentCode = t.Code }).FirstOrDefault(); //Tuple<string, string> d = code.Select(x => new Tuple<string, string>(x.CompanyCode, x.DepartmentCode)).FirstOrDefault(); //int max = from t in this.Indents int maxValue = 1; try { var i = this.Indents.Count(x => x.DepartmentID.Equals(indent.DepartmentID) && x.CreatedDate.Value.Year.Equals(DateTime.Now.Year)); maxValue += i; } catch { } indent.IndentNumber = code.CompanyCode + "-" + code.DepartmentCode + "-" + DateTime.UtcNow.Year + "-" + maxValue.ToString().PadLeft(4, '0'); var dr = (from t in this.DepartmentRoles join u in this.Users on t.FunctionHead equals u.UserID join u1 in this.Users on t.SVP equals u1.UserID where t.DepartmentID == indent.DepartmentID && t.BranchID == indent.BranchID select new { FunctionHead = u.Name, SVP = u1.Name }).FirstOrDefault(); indent.CreatedDate = DateTime.UtcNow; indent.FunctionHead = dr.FunctionHead; indent.SeniorVicePresident = dr.SVP; Indents.Add(indent); } else { Indent u = this.Indents.Where(s => s.IndentID == indent.IndentID).FirstOrDefault <Indent>(); // change contact in disconnected mode (out of DBContext scope) if (u != null) { //u.IndentDate = indent.IndentDate.HasValue ? indent.IndentDate.Value : (DateTime?) null; u.Indentor = indent.Indentor; u.IndentorRemarks = indent.IndentorRemarks; u.BranchID = indent.BranchID; u.DepartmentID = indent.DepartmentID; u.Client_Domain = indent.Client_Domain; u.ProjectStatusID = indent.ProjectStatusID; u.ReasonID = indent.ReasonID; u.LocationTypeID = indent.LocationTypeID; u.EmploymentTypeID = indent.EmploymentTypeID; u.ContractMonths = indent.ContractMonths; u.StaffingModeID = indent.StaffingModeID; u.Technologies = indent.Technologies; u.TechnicalSkills = indent.TechnicalSkills; u.BehaviouralSkills = indent.BehaviouralSkills; u.PositionTitle = indent.PositionTitle; u.NoOfPositions = indent.NoOfPositions; u.MinExperiance = indent.MinExperiance; u.MaxExperiance = indent.MaxExperiance; u.VisaType = indent.VisaType; u.TargetJoinDate = indent.TargetJoinDate.HasValue ? indent.TargetJoinDate.Value : (DateTime?)null; u.InterviewPanel1 = indent.InterviewPanel1; u.InterviewPanel2 = indent.InterviewPanel2; u.ReportingManager = indent.ReportingManager; u.Qualification = indent.Qualification; u.Others = indent.Others; u.FunctionHead = indent.FunctionHead; //u.FunctionHeadStatusDate = indent.FunctionHeadStatusDate.HasValue ? indent.FunctionHeadStatusDate.Value : (DateTime?)null; ; u.FunctionHeadRemarks = indent.FunctionHeadRemarks; u.SeniorVicePresident = indent.SeniorVicePresident; //u.SeniorVicePresidentStatusDate = indent.SeniorVicePresidentStatusDate.HasValue ? indent.SeniorVicePresidentStatusDate.Value : (DateTime?)null; ; u.SeniorVicePresidentRemarks = indent.SeniorVicePresidentRemarks; u.JobDescription = indent.JobDescription; u.UploadFile_Indents = indent.UploadFile_Indents; u.DeploymentLocation = indent.DeploymentLocation; u.Indent_Status = indent.Indent_Status; u.StatusChangedBy = indent.StatusChangedBy; u.ModifiedBy = indent.ModifiedBy; u.ModifiedDate = DateTime.UtcNow; } this.Entry(u).State = EntityState.Modified; } this.SaveChanges(); return(indent.IndentID); } catch { throw; } }