Beispiel #1
0
        public Result <Skill> Save(Skill userinfo)
        {
            var result = new Result <Skill>();

            try
            {
                DbContext.Skills.FirstOrDefault(u => u.SkillId == userinfo.SkillId);
                var objtosave = DbContext.Skills.FirstOrDefault(u => u.SkillId == userinfo.SkillId);
                if (objtosave == null)
                {
                    objtosave = new Skill();
                    DbContext.Skills.Add(objtosave);
                }
                objtosave.SkillName  = userinfo.SkillName;
                objtosave.CategoryId = userinfo.CategoryId;



                if (!IsValid(objtosave, result))
                {
                    return(result);
                }
                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
Beispiel #2
0
        private bool IsValid(Skill obj, Result <Skill> result)
        {
            if (!ValidationHelper.IsStringValid(obj.SkillName))
            {
                result.HasError = true;
                result.Message  = "Invalid SkillName";
                return(false);
            }
            if (!ValidationHelper.IsStringValid(obj.CategoryId.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid CategoryId";
                return(false);
            }


            return(true);
        }
Beispiel #3
0
        private Skill ConvertToEntity(DataRow row)
        {
            try
            {
                Skill u = new Skill();
                u.SkillId    = Int32.Parse(row["SkillID"].ToString());
                u.CategoryId = Int32.Parse(row["CategoryID"].ToString());

                u.SkillName = row["SkillName"].ToString();



                return(u);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #4
0
        public List <Skill> GetAll()
        {
            var result = new List <Skill>();

            try
            {
                string query = "select * from Skill";
                var    dt    = DataAccess.GetDataTable(query);

                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Skill u = ConvertToEntity(dt.Rows[i]);
                        result.Add(u);
                    }
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }