public Result <ProjectSkills> Save(ProjectSkills userinfo) { var result = new Result <ProjectSkills>(); try { var objtosave = DbContext.ProjectSkills.FirstOrDefault(u => u.PostID == userinfo.PostID); if (objtosave == null) { objtosave = new ProjectSkills(); DbContext.ProjectSkills.Add(objtosave); } objtosave.SkillID = userinfo.SkillID; if (!IsValid(objtosave, result)) { return(result); } DbContext.SaveChanges(); } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
private bool IsValid(ProjectSkills obj, Result <ProjectSkills> result) { if (!ValidationHelper.IsStringValid(obj.SkillID.ToString())) { result.HasError = true; result.Message = "Invalid SkillID"; return(false); } return(true); }
private ProjectSkills ConvertToEntity(DataRow row) { try { ProjectSkills u = new ProjectSkills(); u.PostID = Int32.Parse(row["PostId"].ToString()); u.SkillID = Int32.Parse(row["SkillId"].ToString()); return(u); } catch (Exception) { return(null); } }
public Result <ProjectSkills> Save(ProjectSkills ProjectSkills) { var result = new Result <ProjectSkills>(); try { string query = "select * from ProjectSkill where PostID=" + ProjectSkills.PostID; var dt = DataAccess.GetDataTable(query); if (dt == null || dt.Rows.Count == 0) { ProjectSkills.PostID = GetID(); query = "insert into ProjectSkill values(" + ProjectSkills.PostID + "," + ProjectSkills.SkillID + ")"; } else { query = "update ProjectSkill set SkillID=" + ProjectSkills.SkillID + " where PostID=" + ProjectSkills.PostID; } result.HasError = DataAccess.ExecuteQuery(query) <= 0; if (result.HasError) { result.Message = "Something Went Wrong"; } else { result.Data = ProjectSkills; } } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
public List <ProjectSkills> GetAllskill(int id) { var result = new List <ProjectSkills>(); try { string query = "select * from ProjectSkill where skillid=" + id; var dt = DataAccess.GetDataTable(query); if (dt != null && dt.Rows.Count != 0) { for (int i = 0; i < dt.Rows.Count; i++) { ProjectSkills u = ConvertToEntity(dt.Rows[i]); result.Add(u); } } } catch (Exception ex) { } return(result); }