/// <summary /> /// <exception cref="ArgumentNullException">Throws an exception when dto is null</exception> public virtual async Task <TEntityDTO> AddAsync(TEntityCreateDTO dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } var entity = Mapper.Map <TEntity>(dto); var additionResult = await Context.Set <TEntity>().AddAsync(entity); await Context.SaveChangesAsync(); var createdEntity = await Context.Set <TEntity>().FindAsync(additionResult.Entity.Id); return(Mapper.Map <TEntityDTO>(createdEntity)); }
public async Task <UserDTO> Register(NewUserDTO creatingUser) { var userSN = new NewUserSocialNetworkDTO() { UId = creatingUser.UId, ProviderName = creatingUser.ProviderName, SocialNetworkUrl = creatingUser.ProviderUrl, }; var user = _mapper.Map <User>(creatingUser); user.CreatedAt = DateTime.Now; _context.Add(user); await _context.SaveChangesAsync(); var userDto = _mapper.Map <UserDTO>(user); userSN.UserId = userDto.Id; var userSNEntity = _mapper.Map <UserSocialNetwork>(userSN); _context.Add(userSNEntity); await _context.SaveChangesAsync(); var emailModel = _emailBuilder.GetSignUpLetter(creatingUser.Email, creatingUser.FirstName); await _emailService.SendEmailAsync(new List <string> { emailModel.Email }, emailModel.Subject, emailModel.Title, emailModel.Body); return(_mapper.Map <UserDTO>(user)); }
public async Task <ProjectRemoteTriggerDTO> CreateProejectTrigger(NewProjectRemoteTriggerDTO triggerDTO) { if (triggerDTO == null) { throw new NullDTOException(typeof(NewProjectRemoteTriggerDTO)); } var project = await _context.Projects.FirstOrDefaultAsync(p => p.Id == triggerDTO.ProjectId); if (project == null) { throw new NotFoundException("Project", triggerDTO.ProjectId); } var trigger = _mapper.Map <ProjectRemoteTrigger>(triggerDTO); _context.Add(trigger); await _context.SaveChangesAsync(); return(_mapper.Map <ProjectRemoteTriggerDTO>(trigger)); }
public async Task <UserDTO> Register(NewUserDTO creatingUser) { var userSNEntity = new UserSocialNetwork() { UId = creatingUser.UId, ProviderName = creatingUser.ProviderName, SocialNetworkUrl = creatingUser.ProviderUrl, }; var user = _mapper.Map <User>(creatingUser, opt => opt.AfterMap((src, dst) => { dst.CreatedAt = DateTime.Now; dst.UserSocialNetworks = new List <UserSocialNetwork> { userSNEntity }; })); _context.Add(user); await _context.SaveChangesAsync(); var emailModel = _emailBuilder.GetSignUpLetter(creatingUser.Email, creatingUser.FirstName); await _emailService.SendEmailAsync(new List <string> { emailModel.Email }, emailModel.Subject, emailModel.Title, emailModel.Body); return(_mapper.Map <UserDTO>(user)); }
public async Task <BuildHistory> PrepareBuild(int projectId, string buildAuthorUsername, string triggeredBranch) { var user = await GetUserByUsername(buildAuthorUsername); var build = new BuildHistory(); build.ProjectId = projectId; build.PerformerId = user?.Id; build.BuildStatus = BuildStatus.Pending; build.StartedAt = DateTime.Now; build.Number = _context.BuildHistories.Count(b => b.ProjectId == projectId) + 1; var lastCommit = await _synchronizationService.GetLastProjectCommit(projectId, triggeredBranch); build.CommitHash = lastCommit.Hash; _context.Add(build); await _context.SaveChangesAsync(); return(build); }
public async Task <MessageDTO> SendMessage(MessageDTO messageDTO) { if (messageDTO == null) { throw new NullReferenceException(); } var entity = _mapper.Map <Message>(messageDTO); entity.CreatedAt = DateTime.Now; var result = await _context.Messages.AddAsync(entity); await _context.SaveChangesAsync(); var createdEntity = await _context.Messages.FindAsync(result.Entity.Id); var dto = _mapper.Map <MessageDTO>(createdEntity); dto.Sender = _mapper.Map <UserDTO>(await _context.Users.FindAsync(dto.SenderId)); _producer.Send(JsonConvert.SerializeObject(dto, CamelCaseProperties), dto.Text); return(dto); }
public async Task MarkAsRead(int notificationId) { (await _context.Notifications.FindAsync(notificationId)).IsRead = true; await _context.SaveChangesAsync(); }