/// <summary> /// This method updates the specified entity excluding the user object. /// </summary> /// <param name="entity">The entity parameter represents the updated project object.</param> public override void Update(Project entity) { entity = UpdateUpdatedField(entity); DbSet.Attach(entity); if (entity.User != null) { DbContext.Entry(entity.User) .Property(x => x.Email) .IsModified = false; DbContext.Entry(entity.User) .State = EntityState.Unchanged; } if (entity.ProjectIcon == null) { DbContext.Entry(entity) .Entity.ProjectIconId = null; } DbSet.Update(entity); SetLikes(entity); ESProjectDTO projectToSync = ProjectConverter.ProjectToESProjectDTO(entity); taskPublisher.RegisterTask(Newtonsoft.Json.JsonConvert.SerializeObject(projectToSync), Subject.ELASTIC_CREATE_OR_UPDATE); }
/// <summary> /// This method removes the project from the database and ES Index. /// </summary> /// <param name="entity">The entity parameter represents a project to be removed.</param> public override void Remove(Project entity) { base.Remove(entity); SetLikes(entity); ESProjectDTO projectToSync = ProjectConverter.ProjectToESProjectDTO(entity); taskPublisher.RegisterTask(Newtonsoft.Json.JsonConvert.SerializeObject(projectToSync), Subject.ELASTIC_DELETE); }
/// <summary> /// This method redacts user email from the Project if isPublic setting is set to false. /// This method asynchronously removes the project from the database and ES Index coupled to the given id. /// </summary> /// <param name="id">The project parameter represents unique identifier.</param> /// <returns> /// The task wherein the removal of the project from the database is executed. /// </returns> public override Task RemoveAsync(int id) { Project entity = DbSet.Find(id); SetLikes(entity); ESProjectDTO projectToSync = ProjectConverter.ProjectToESProjectDTO(entity); taskPublisher.RegisterTask(Newtonsoft.Json.JsonConvert.SerializeObject(projectToSync), Subject.ELASTIC_DELETE); return(base.RemoveAsync(id)); }
/// <summary> /// This method adds the given project to the database and ES Index. /// </summary> /// <param name="entity">The entity parameter represents a project to be added.</param> public override void Add(Project entity) { base.Add(entity); base.Save(); Console.WriteLine("Add method id: " + entity.Id); SetLikes(entity); ESProjectDTO projectToSync = ProjectConverter.ProjectToESProjectDTO(entity); taskPublisher.RegisterTask(Newtonsoft.Json.JsonConvert.SerializeObject(projectToSync), Subject.ELASTIC_CREATE_OR_UPDATE); }
public async Task SyncProjectToES(Project project) { Project projectToSync = await FindAsync(project.Id); if (projectToSync == null) { throw new NotFoundException("Project to sync was not found"); } ESProjectDTO eSProjectDTO = ProjectConverter.ProjectToESProjectDTO(projectToSync); taskPublisher.RegisterTask(Newtonsoft.Json.JsonConvert.SerializeObject(eSProjectDTO), Subject.ELASTIC_CREATE_OR_UPDATE); }
public override void AddRange(IEnumerable <Project> entities) { List <Project> entityList = entities.ToList(); for (int i = 0; i < entityList.Count; i++) { entityList[i] = UpdateCreatedField(entityList[i]); entityList[i] = UpdateUpdatedField(entityList[i]); } DbSet.AddRange(entityList); entityList.ForEach(x => { SetLikes(x); ESProjectDTO projectToSync = ProjectConverter.ProjectToESProjectDTO(x); taskPublisher.RegisterTask(Newtonsoft.Json.JsonConvert.SerializeObject(projectToSync), Subject.ELASTIC_CREATE_OR_UPDATE); }); }