public string CreateCommunication(CreateCommunicationDto data) { try { if (data.SenderId < 1 || data.ReceiverId < 1) { throw new InvalidSenderOrReceiverException(data.SenderId, data.ReceiverId); } var communicationForType = _context.Communications .Where(x => x.Type == data.Type); var record = data.Type == Type.External ? $"CE00000{communicationForType.Count() + 1}" : $"CI00000{communicationForType.Count() + 1}"; var newCommunication = new Communication(record, data.SenderId, data.ReceiverId, data.Type); _context.Add(newCommunication); _context.SaveChanges(); return(record); } catch (InvalidSenderOrReceiverException exception) { return(exception.Message); } }
public IActionResult Create(CreateCommunicationDto data) { var response = _mvmService.CreateCommunication(data); if (response == null) { return(BadRequest(new { message = "Information is incorrect" })); } return(Ok(response)); }