private bool IsValid(RatingOwner obj, Result <RatingOwner> result) { if (!ValidationHelper.IsStringValid(obj.CommunicationSkill.ToString())) { result.HasError = true; result.Message = "Invalid CommunicationSkill"; return(false); } if (!ValidationHelper.IsStringValid(obj.Reliability.ToString())) { result.HasError = true; result.Message = "Invalid Reliability"; return(false); } if (!ValidationHelper.IsStringValid(obj.OnWord.ToString())) { result.HasError = true; result.Message = "Invalid OnWord"; return(false); } if (!ValidationHelper.IsStringValid(obj.Behaviour.ToString())) { result.HasError = true; result.Message = "Invalid Behaviour"; return(false); } return(true); }
public Result <RatingOwner> Save(RatingOwner userinfo) { var result = new Result <RatingOwner>(); try { var objtosave = DbContext.RatingOwners.FirstOrDefault(u => u.UserId == userinfo.UserId); if (objtosave == null) { objtosave = new RatingOwner(); DbContext.RatingOwners.Add(objtosave); } objtosave.CommunicationSkill = userinfo.CommunicationSkill; objtosave.Reliability = userinfo.Reliability; objtosave.OnWord = userinfo.OnWord; objtosave.Behaviour = userinfo.Behaviour; if (!IsValid(objtosave, result)) { return(result); } DbContext.SaveChanges(); } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
public Result <RatingOwner> Save(RatingOwner RatingOwner) { var result = new Result <RatingOwner>(); try { string query = "select * from RatingOwner where UserId=" + RatingOwner.UserId; var dt = DataAccess.GetDataTable(query); if (dt == null || dt.Rows.Count == 0) { // RatingOwner.UserId = GetID(); query = "insert into RatingOwner values(" + RatingOwner.UserId + "," + RatingOwner.CommunicationSkill + "," + RatingOwner.Reliability + "," + RatingOwner.OnWord + "," + RatingOwner.Behaviour + ")"; } else { query = "update RatingOwner set CommunicationSkill=" + RatingOwner.CommunicationSkill + ",Reliability=" + RatingOwner.Reliability + ",OnWord=" + RatingOwner.OnWord + ",Behaviour=" + RatingOwner.Behaviour + " where UserId=" + RatingOwner.UserId; } //if (!IsValid(RatingOwner, result)) //{ // return result; //} result.HasError = DataAccess.ExecuteQuery(query) <= 0; if (result.HasError) { result.Message = "Something Went Wrong"; } else { result.Data = RatingOwner; } } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
private RatingOwner ConvertToEntity(DataRow row) { try { RatingOwner u = new RatingOwner(); u.UserId = Int32.Parse(row["UserId"].ToString()); u.CommunicationSkill = Int32.Parse(row["CommunicationSkill"].ToString()); u.Reliability = Int32.Parse(row["Reliability"].ToString()); u.OnWord = Int32.Parse(row["OnWord"].ToString()); u.Behaviour = Int32.Parse(row["Behaviour"].ToString()); return(u); } catch (Exception) { return(null); } }
//private int GetID() //{ // string query = "select * from RatingOwner order by UserId desc"; // var dt = DataAccess.GetDataTable(query); // int id = 1; // if (dt != null && dt.Rows.Count != 0) // id = Int32.Parse(dt.Rows[0]["ID"].ToString()) + 1; // return id; //} public List <RatingOwner> GetAll() { var result = new List <RatingOwner>(); try { string query = "select * from RatingOwner"; var dt = DataAccess.GetDataTable(query); if (dt != null && dt.Rows.Count != 0) { for (int i = 0; i <= dt.Rows.Count; i++) { RatingOwner u = ConvertToEntity(dt.Rows[i]); result.Add(u); } } } catch (Exception ex) { return(result); } return(result); }