public bool CreateItem <T>(T item, ICrudRepository <T> repository, GenericOperationResult <T> or) where T : class, new() { if (item == null) { or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.NullObjectReference)); or.SetFail(); return(false); } try { var success = repository.CreateItem(item); if (success) { or.SetData(item); return(true); } else { or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError)); return(false); } } catch (Exception e) { or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError)); return(false); } }
public GenericOperationResult <IEnumerable <Quiz> > GetAvailableQuies(string studentName, QuizGetType type) { GenericOperationResult <IEnumerable <Quiz> > result = OperationResult.GetGenericResultObject <IEnumerable <Quiz> >(); // check student User student = _userService.GetUser(studentName); if (student == null) { result.AddMessage(_messagesService.GetErrorMessage(ErrorMessageKeys.UserNotFound)); return(result); } else { switch (type) { case QuizGetType.Pregenarated: return(GetPredefinedQuizes(student)); break; } } return(result); }
public bool GetItem <T>(int id, ICrudRepository <T> repository, GenericOperationResult <T> or) where T : class, new() { if (id == 0) { or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.InvalidId)); return(false); } try { var item = repository.GetItem(id); or.SetData(item); return(true); } catch (Exception e) { or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError)); return(false); } }
public bool GetItems <T>(ICrudRepository <T> repository, GenericOperationResult <IEnumerable <T> > or) { try { var items = repository.GetAllItems(); or.SetData(items); return(true); } catch (Exception e) { or.AddMessage(_localizedMessagesService.GetErrorMessage(ErrorMessageKeys.RepositoryError)); return(false); } }