Ejemplo n.º 1
0
        public Result <SkillCategory> Save(SkillCategory userinfo)
        {
            var result = new Result <SkillCategory>();

            try
            {
                DbContext.SkillCategories.FirstOrDefault(u => u.CategoryId == userinfo.CategoryId);
                var objtosave = DbContext.SkillCategories.FirstOrDefault(u => u.CategoryId == userinfo.CategoryId);
                if (objtosave == null)
                {
                    objtosave = new SkillCategory();
                    DbContext.SkillCategories.Add(objtosave);
                }

                objtosave.CategoryId   = userinfo.CategoryId;
                objtosave.CategoryName = userinfo.CategoryName;



                if (!IsValid(objtosave, result))
                {
                    return(result);
                }
                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
Ejemplo n.º 2
0
        private SkillCategory ConvertToEntity(DataRow row)
        {
            try
            {
                SkillCategory u = new SkillCategory();
                u.CategoryId   = Int32.Parse(row["CategoryID"].ToString());
                u.CategoryName = row["CategoryName"].ToString();

                return(u);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        private bool IsValid(SkillCategory obj, Result <SkillCategory> result)
        {
            if (!ValidationHelper.IsStringValid(obj.CategoryId.ToString()))
            {
                result.HasError = true;
                result.Message  = "Invalid CategoryId";
                return(false);
            }

            if (!ValidationHelper.IsStringValid(obj.CategoryName))
            {
                result.HasError = true;
                result.Message  = "Invalid CategoryName";
                return(false);
            }


            return(true);
        }
Ejemplo n.º 4
0
        public List <SkillCategory> GetAll()
        {
            var result = new List <SkillCategory>();

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

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