public ActionResult DeleteSkillDefined(SkillDefinedModel model) { try { #region " [ Declaration ] " SkillDefinedService _service = new SkillDefinedService(); #endregion #region " [ Main process ] " model.CreateBy = UserID; model.DeleteBy = UserID; model.DeleteDate = DateTime.Now; #endregion //Call to service return(this.Json(_service.Delete(model), JsonRequestBehavior.AllowGet)); } catch (ServiceException serviceEx) { throw serviceEx; } catch (DataAccessException accessEx) { throw accessEx; } catch (Exception ex) { throw new ControllerException(FILE_NAME, "DeleteSkillDefined", UserID, ex); } }
/// <summary> /// Delete /// </summary> /// <param name="model">Skill defined model</param> /// <returns>ResponseStatusCodeHelper</returns> public ResponseStatusCodeHelper Delete(SkillDefinedModel model) { try { using (var _context = new TDHEntities()) { CM_SKILL_DEFINDED _md = _context.CM_SKILL_DEFINDED.FirstOrDefault(m => m.id == model.ID && !m.deleted && m.created_by == model.CreateBy); if (_md == null) { throw new DataAccessException(FILE_NAME, "Delete", model.CreateBy); } _context.CM_SKILL_DEFINDED.Remove(_md); _context.Entry(_md).State = EntityState.Deleted; _context.SaveChanges(); } } catch (DataAccessException fieldEx) { throw fieldEx; } catch (Exception ex) { throw new ServiceException(FILE_NAME, "Save", model.CreateBy, ex); } Notifier.Notification(model.CreateBy, Message.DeleteSuccess, Notifier.TYPE.Success); return(ResponseStatusCodeHelper.Success); }
/// <summary> /// Get item by id and owner /// </summary> /// <param name="model">skill defined model</param> /// <returns>MoneyAccountModel. Throw exception if not found or get some error</returns> public SkillDefinedModel GetItemByID(SkillDefinedModel model) { try { using (var _context = new TDHEntities()) { CM_SKILL_DEFINDED _md = _context.CM_SKILL_DEFINDED.FirstOrDefault(m => m.id == model.ID && !m.deleted && m.created_by == model.CreateBy); if (_md == null) { throw new DataAccessException(FILE_NAME, "GetItemByID", model.CreateBy); } var _return = new SkillDefinedModel() { ID = _md.id, Name = _md.name, Ordering = _md.ordering, Description = _md.description, Point = _md.point }; return(_return); } } catch (DataAccessException fieldEx) { throw fieldEx; } catch (Exception ex) { throw new ServiceException(FILE_NAME, "GetItemByID", model.CreateBy, ex); } }
/// <summary> /// Save /// </summary> /// <param name="model">Skill defined model</param> /// <returns>ResponseStatusCodeHelper</returns> public ResponseStatusCodeHelper Save(SkillDefinedModel model) { try { using (var _context = new TDHEntities()) { CM_SKILL_DEFINDED _md = new CM_SKILL_DEFINDED(); if (model.Insert) { _md.id = Guid.NewGuid(); } else { _md = _context.CM_SKILL_DEFINDED.FirstOrDefault(m => m.id == model.ID && !m.deleted && m.created_by == model.CreateBy); if (_md == null) { throw new DataAccessException(FILE_NAME, "Save", model.CreateBy); } } _md.skill_id = model.SkillID; _md.name = model.Name; _md.ordering = model.Ordering; _md.description = model.Description; _md.publish = true; //Create or edit, only change the name and type if (model.Insert) { _md.created_by = model.CreateBy; _md.created_date = DateTime.Now; _context.CM_SKILL_DEFINDED.Add(_md); _context.Entry(_md).State = EntityState.Added; } else { _md.updated_by = model.UpdateBy; _md.updated_date = DateTime.Now; _context.CM_SKILL_DEFINDED.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); }