Example #1
0
        public JsonResult UpdateCategory(EmpCategory category)
        {
            CommonResponse cr = new CommonResponse();

            try
            {
                var pro = _context.EmpCategory.Where(e => e.CategoryID == category.CategoryID).FirstOrDefault();
                pro.CategoryName      = category.CategoryName;
                pro.CategoryIsTeacher = category.CategoryIsTeacher;
                pro.UpdateDate        = DateTime.Now;
                pro.UpdateBy          = User.Identity.Name;
                pro.SetDate();
                _context.EmpCategory.Update(pro);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                cr.message = ex.Message;
                cr.results = Constant.FAILED;
            }
            return(new JsonResult(cr));
        }
Example #2
0
        public JsonResult AddCategory([FromBody] EmpCategory category)
        {
            CommonResponse cr = new CommonResponse();

            try
            {
                var isExist = DataAccess.Instance.CommonServices.IsExist("Emp_Category", "CategoryName = '" + category.CategoryName + "' ");
                if (isExist)
                {
                    throw new Exception("Category Already Exist.");
                }
                category.AddDate = DateTime.Now;
                category.AddBy   = User.Identity.Name;
                category.SetDate();
                _context.EmpCategory.Add(category);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                cr.message = ex.Message;
                cr.results = Constant.FAILED;
            }
            return(new JsonResult(cr));
        }