public DescriptiveResponse <bool> Delete(TId id) { try { // If id is zero or empty if (id.Equals(default(TId))) { // Return input is null response return(DescriptiveResponse <bool> .Error(ErrorStatus.INPUT_IS_NULL)); } // Delete item by id _writeRepository.Delete(id); // Return success response with delete result return(DescriptiveResponse <bool> .Success(_writeRepository.UnitOfWork.SaveChanges())); } catch (Exception ex) { // Log error Logger.Log(ex); // return unexpected error return(DescriptiveResponse <bool> .Error(ErrorStatus.UNEXPECTED_ERROR)); } }
public DescriptiveResponse <TRead> GetItem(TId id) { try { // If id is zero or empty if (id.Equals(default(TId))) { // Return input is null response return(DescriptiveResponse <TRead> .Error(ErrorStatus.INPUT_IS_NULL)); } // Find item by id TRead item = _readRepository.GetSingleOrDefault(id); // If exist if (item != null) { // Return success response with item return(DescriptiveResponse <TRead> .Success(item)); } // Return not found error response return(DescriptiveResponse <TRead> .Error(ErrorStatus.NOT_FOUND)); } catch (Exception ex) { // Log error Logger.Log(ex); // return unexpected error return(DescriptiveResponse <TRead> .Error(ErrorStatus.UNEXPECTED_ERROR)); } }
public DescriptiveResponse <int> Put(ContentRequirement contentRequirement) { if (!ModelState.IsValid) { return(DescriptiveResponse <int> .Error(ErrorStatus.INPUT_INVAILD)); } return(Manager.Save(contentRequirement)); }
public DescriptiveResponse <int> Put(ContentTargetViewer contentTargetViewer) { if (!ModelState.IsValid) { return(DescriptiveResponse <int> .Error(ErrorStatus.INPUT_INVAILD)); } return(Manager.Save(contentTargetViewer)); }
public DescriptiveResponse <int> Put(Section Section) { if (!ModelState.IsValid) { return(DescriptiveResponse <int> .Error(ErrorStatus.INPUT_INVAILD)); } return(Manager.Save(Section)); }
public override DescriptiveResponse <int> Post(ContentGoal contentgoal) { if (!ModelState.IsValid) { return(DescriptiveResponse <int> .Error(ErrorStatus.INPUT_INVAILD)); } return(Manager.Save(contentgoal)); }
public DescriptiveResponse <IEnumerable <Read.Channel> > GetChannelperUser(int userid) { var channelsperuser = _readRepository.GetAll().Where(s => s.UserId == userid).ToList(); if (channelsperuser.Count == 0) { return(DescriptiveResponse <IEnumerable <Read.Channel> > .Error(ErrorStatus.NOT_FOUND)); } return(DescriptiveResponse <IEnumerable <Read.Channel> > .Success(channelsperuser)); }
public DescriptiveResponse <IEnumerable <Read.Content> > GetChannelperUser(int channelid) { var contents = _readRepository.GetAll().Where(s => s.ChannelId == channelid).ToList(); if (contents.Count == 0) { return(DescriptiveResponse <IEnumerable <Read.Content> > .Error(ErrorStatus.NOT_FOUND)); } return(DescriptiveResponse <IEnumerable <Read.Content> > .Success(contents)); }
private DescriptiveResponse <List <LookupObject <TId, TUId> > > FilterLookup <TId, TUId>(string lookupName, List <FilterSearchCriteria> filters = null, bool includeExtraColumns = false, bool includeDeleted = false) where TId : IEquatable <TId> where TUId : struct { var injected = PreventSQLInjection <List <LookupObject <TId, TUId> > >(lookupName); if (injected != null) { return(injected); } try { // New UnitOfWork using (IUnitOfWork unitOfWork = new UnitOfWork()) { // New dynmic repository IDynamicRepository repository = new DynamicRepository(unitOfWork); // Get all Coulmns List <DbColumn> columns = repository.GetColumns($"dbo.LK_{lookupName}"); StringBuilder query = new StringBuilder(); // Create Query CreateQuery(query, columns, lookupName); // Apply Filter on query ApplyFilters <TUId>(query, includeDeleted, columns.Any(col => col.Name.ToLower() == LookUpConsts.CreatedByField.ToLower()), filters, columns); // Execute SQL Query List <LookupObject <TId, TUId> > lookupCollection = repository.ExecuteQuery <LookupObject <TId, TUId> >(query.ToString()); lookupCollection.ForEach(item => item.LookupObjectType = item.UserId.HasValue ? LookupObjectType.User : LookupObjectType.System); if (includeExtraColumns) { GetExtraColumns(repository, lookupCollection, columns, lookupName, includeDeleted, filters); } return(DescriptiveResponse <List <LookupObject <TId, TUId> > > .Success(lookupCollection)); } } catch (Exception ex) { Logger.Log(ex); return(DescriptiveResponse <List <LookupObject <TId, TUId> > > .Error(ErrorStatus.UNEXPECTED_ERROR)); } }
public DescriptiveResponse <int> Put(Write.Channel channel) { if (!ModelState.IsValid) { return(DescriptiveResponse <int> .Error(ErrorStatus.INPUT_INVAILD)); } if (CheckNameforedit(channel.Name, channel.Id)) { return(DescriptiveResponse <int> .Error(ErrorStatus.ALREADY_EXIST)); } if (CheckChannelCategoryPerInstructorforedit(channel.channelType, channel.CategoryId, channel.Id)) { return(DescriptiveResponse <int> .Error(ErrorStatus.ALREADY_EXIST)); } return(Manager.Save(channel)); }
public override DescriptiveResponse <int> Post(Write.Channel channel) { if (!ModelState.IsValid) { return(DescriptiveResponse <int> .Error("" + ModelState)); } if (CheckName(channel.Name)) { return(DescriptiveResponse <int> .Error(ErrorStatus.ALREADY_EXIST)); } if (CheckChannelCategoryPerInstructor(channel.channelType, channel.CategoryId)) { return(DescriptiveResponse <int> .Error(ErrorStatus.ALREADY_EXIST)); } return(Manager.Save(channel)); }
public DescriptiveResponse <TId> Save(TWrite item) { try { // If item is null if (item == null) { // Return error response with input is null error return(DescriptiveResponse <TId> .Error(ErrorStatus.INPUT_IS_NULL)); } // TWrite is manged entity if (item is ManagedEntity <TId, TUId> ) { ManagedEntity <TId, TUId> managedEntity = item as ManagedEntity <TId, TUId>; // If model in adding mode if (managedEntity.Id.Equals(default(TId))) { // Update creation log properties managedEntity.CreatedBy = UserUtility <TUId> .CurrentUser.UserId; managedEntity.CreationDate = DateTime.UtcNow; } else // If model in update mode { //Update modification log properties managedEntity.LastModifiedBy = UserUtility <TUId> .CurrentUser.UserId; managedEntity.LastModifiedDate = DateTime.UtcNow; } } // Attach entity _writeRepository.Attach(item); // Save Changes _writeRepository.UnitOfWork.SaveChanges(); return(DescriptiveResponse <TId> .Success(item.Id)); } catch (Exception ex) { Logger.Log(ex); return(DescriptiveResponse <TId> .Error(ErrorStatus.UNEXPECTED_ERROR)); } }
public DescriptiveResponse <FilteredCollection <TRead> > FilterCollection(Filtration filter) { try { // Add userId in case of entity of type managed entity if (typeof(TRead).IsSubclassOf(typeof(ManagedEntity <TId, TUId>))) { if (filter == null) { filter = new Filtration(); } if (filter.SearchCriteria == null) { filter.SearchCriteria = new List <FilterSearchCriteria>(); } filter.SearchCriteria.Add(new FilterSearchCriteria { Field = "CreatedBy", Operator = LogicalOperator.Equal, SearchKey = UserUtility <TUId> .CurrentUser.UserId.ToString() }); } // Find all items that match filteration FilteredCollection <TRead> filteredCollection = _readRepository.Find(filter); // Return success response return(DescriptiveResponse <FilteredCollection <TRead> > .Success(filteredCollection)); } catch (Exception ex) { // Log error Logger.Log(ex); // return unexpected error return(DescriptiveResponse <FilteredCollection <TRead> > .Error(ErrorStatus.UNEXPECTED_ERROR)); } }