/// <summary>
 /// Delete
 /// </summary>
 /// <param name="model"></param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper Delete(CheckListItemModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             WK_CHECKLIST_ITEM _md = context.WK_CHECKLIST_ITEM.FirstOrDefault(m => m.id == model.ID && !m.deleted);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "Delete", model.CreateBy);
             }
             _md.deleted     = true;
             _md.delete_by   = model.DeleteBy;
             _md.description = model.description;
             _md.delete_date = DateTime.Now;
             context.WK_CHECKLIST_ITEM.Attach(_md);
             context.Entry(_md).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "Delete", model.CreateBy, ex);
     }
     Notifier.Notification(model.CreateBy, Message.DeleteSuccess, Notifier.TYPE.Success);
     return(ResponseStatusCodeHelper.Success);
 }
 /// <summary>
 /// Get item
 /// </summary>
 /// <param name="model"></param>
 /// <returns>CheckListGruopModel. Throw exception if not found or get some error</returns>
 public CheckListItemModel GetItemByID(CheckListItemModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             WK_CHECKLIST_ITEM _md = context.WK_CHECKLIST_ITEM.FirstOrDefault(m => m.id == model.ID && !m.deleted);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "GetItemByID", model.CreateBy);
             }
             return(new CheckListItemModel()
             {
                 ID = _md.id,
                 title = _md.title,
                 description = _md.description,
                 CreateDate = _md.create_date
             });
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "GetItemByID", model.CreateBy, ex);
     }
 }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="model"></param>
        /// <returns>ResponseStatusCodeHelper</returns>
        public ResponseStatusCodeHelper Save(CheckListItemModel model)
        {
            try
            {
                using (var context = new TDHEntities())
                {
                    WK_CHECKLIST_ITEM _md = new WK_CHECKLIST_ITEM();
                    if (model.Insert)
                    {
                        _md.id = Guid.NewGuid();
                    }
                    else
                    {
                        _md = context.WK_CHECKLIST_ITEM.FirstOrDefault(m => m.id == model.ID && !m.deleted);
                        if (_md == null)
                        {
                            throw new DataAccessException(FILE_NAME, "Save", model.CreateBy);
                        }
                    }
                    _md.title       = model.title;
                    _md.description = model.description;
                    _md.update_date = model.updateDate;

                    if (model.Insert)
                    {
                        _md.create_by   = model.CreateBy;
                        _md.create_date = DateTime.Now;
                        context.WK_CHECKLIST_ITEM.Add(_md);
                        context.Entry(_md).State = EntityState.Added;
                    }
                    else
                    {
                        _md.update_by   = model.UpdateBy;
                        _md.update_date = DateTime.Now;
                        context.WK_CHECKLIST_ITEM.Attach(_md);
                        context.Entry(_md).State = EntityState.Modified;
                    }
                    context.SaveChanges();
                }
            }
            catch (DataAccessException fieldEx)
            {
                throw fieldEx;
            }
            catch (Exception ex)
            {
                throw new ServiceException(FILE_NAME, "Save", model.CreateBy, ex);
            }
            if (model.Insert)
            {
                Notifier.Notification(model.CreateBy, Message.InsertSuccess, Notifier.TYPE.Success);
            }
            else
            {
                Notifier.Notification(model.CreateBy, Message.UpdateSuccess, Notifier.TYPE.Success);
            }
            return(ResponseStatusCodeHelper.Success);
        }
 /// <summary>
 /// Check Delete item
 /// </summary>
 /// <param name="model"></param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper CheckDelete(CheckListItemModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             WK_CHECKLIST_ITEM _md = context.WK_CHECKLIST_ITEM.FirstOrDefault(m => m.id == model.ID && !m.deleted);
             if (_md == null)
             {
                 return(ResponseStatusCodeHelper.OK);
             }
         }
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "CheckDelete", model.CreateBy, ex);
     }
     return(ResponseStatusCodeHelper.NG);
 }