/// <summary> /// Delete /// </summary> /// <param name="model">Home navigation model</param> /// <returns>ResponseStatusCodeHelper</returns> public ResponseStatusCodeHelper Delete(HomeNavigationModel model) { try { using (var _context = new TDHEntities()) { WEB_HOME_NAVIGATION _md = _context.WEB_HOME_NAVIGATION.FirstOrDefault(m => m.navigation_id == model.NavigationID); if (_md == null) { throw new DataAccessException(FILE_NAME, "Delete", model.CreateBy); } _context.WEB_HOME_NAVIGATION.Remove(_md); _context.Entry(_md).State = EntityState.Deleted; _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); }
public JsonResult SaveNavigation(HomeNavigationModel model) { try { #region " [ Declaration ] " HomeNavigationService _service = new HomeNavigationService(); #endregion #region " [ Main processing ] " model.CreateBy = UserID; model.UpdateBy = UserID; model.CreateDate = DateTime.Now; model.UpdateDate = DateTime.Now; #endregion //Call to service return(this.Json(_service.Save(model), JsonRequestBehavior.AllowGet)); } catch (ServiceException serviceEx) { throw serviceEx; } catch (DataAccessException accessEx) { throw accessEx; } catch (Exception ex) { throw new ControllerException(FILE_NAME, "SaveNavigation", UserID, ex); } }
/// <summary> /// Save /// </summary> /// <param name="model">Home navigation model</param> /// <returns>ResponseStatusCodeHelper</returns> public ResponseStatusCodeHelper Save(HomeNavigationModel model) { try { using (var _context = new TDHEntities()) { WEB_HOME_NAVIGATION _md = _md = _context.WEB_HOME_NAVIGATION.FirstOrDefault(m => m.navigation_id == model.NavigationID); if (!model.Selected) { return(Delete(model)); } if (_md == null) { _md = new WEB_HOME_NAVIGATION() { id = Guid.NewGuid(), navigation_id = model.NavigationID, ordering = 1 }; _context.WEB_HOME_NAVIGATION.Add(_md); _context.Entry(_md).State = EntityState.Added; } else { _md.ordering = model.Ordering; _context.WEB_HOME_NAVIGATION.Attach(_md); _context.Entry(_md).State = EntityState.Modified; } _context.SaveChanges(); } } catch (Exception ex) { throw new ServiceException(FILE_NAME, "Save", model.CreateBy, ex); } Notifier.Notification(model.CreateBy, Message.UpdateSuccess, Notifier.TYPE.Success); return(ResponseStatusCodeHelper.Success); }