public ConversationReadDto Create(ConversationCreateDto dto) { var firstUser = UserData.Users.FirstOrDefault(e => e.Id == dto.FirstUserId); var secondUser = UserData.Users.FirstOrDefault(e => e.Id == dto.SecondUserId); if (firstUser == null || secondUser == null) { throw new BusinessException("User does not exist", 400); } var conversation = _mapper.Map <Conversation>(dto); _context.Conversations.Add(conversation); _context.SaveChanges(); _logger.Log("Conversation created!"); return(_mapper.Map <ConversationReadDto>(conversation)); }
public UserReadDto Create(UserCreateDto dto) { var user = _mapper.Map <User>(dto); _context.Users.Add(user); _context.SaveChanges(); _logger.Log("User created!"); return(_mapper.Map <UserReadDto>(user)); }
public PersonalReadDto Create(PersonalCreateDto dto) { var personal = _mapper.Map <Personal>(dto); _context.Personal.Add(personal); _context.SaveChanges(); _logger.Log("Personal created!"); return(_mapper.Map <PersonalReadDto>(personal)); }
public AdministratorReadDto Create(AdministratorCreateDto dto) { var admin = _mapper.Map <Administrator>(dto); _context.Administrators.Add(admin); _context.SaveChanges(); _logger.Log("Admin created!"); return(_mapper.Map <AdministratorReadDto>(admin)); }
public CorporateReadDto Create(CorporateCreateDto dto) { var corporate = _mapper.Map <Corporate>(dto); var owner = _context.Users.FirstOrDefault(e => e.Id == dto.OwnerId); if (owner == null) { throw new BusinessException("Owner does not exist", 400); } _context.Corporators.Add(corporate); _context.SaveChanges(); _logger.Log("Corporate created!"); return(_mapper.Map <CorporateReadDto>(corporate)); }
public ServiceReadDto Create(ServiceCreateDto dto) { var user = UserData.Users.FirstOrDefault(e => e.Id == dto.UserId); if (user == null) { throw new BusinessException("User does not exist", 400); } var service = _mapper.Map <Service>(dto); _context.Services.Add(service); _context.SaveChanges(); _logger.Log("Service created!"); return(_mapper.Map <ServiceReadDto>(service)); }
public ProductReadDto Create(ProductCreateDto dto) { var user = UserData.Users.FirstOrDefault(e => e.Id == dto.UserId); if (user == null) { throw new BusinessException("User does not exist", 400); } var product = _mapper.Map <Product>(dto); _context.Products.Add(product); _context.SaveChanges(); _logger.Log("Product created!"); return(_mapper.Map <ProductReadDto>(product)); }
public MessageReadDto Create(MessageCreateDto dto) { var user = UserData.Users.FirstOrDefault(e => e.Id == dto.SenderId); if (user == null) { throw new BusinessException("User does not exist", 400); } var message = _mapper.Map <Message>(dto); _context.Messages.Add(message); _context.SaveChanges(); _logger.Log("Message created!"); return(_mapper.Map <MessageReadDto>(message)); }