public async Task <ActionResult <MailingPort> > Put(int id, PortDTO port) { MailingPort message = (MailingPort)port; if (message == null) { return(BadRequest()); } using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { var mailingPort = await serviceDbContext.MailingPorts.FindAsync(id); mailingPort.PortName = port.Name; await serviceDbContext.SaveChangesAsync(); return(Ok(mailingPort)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }
public async Task <ActionResult <MessageType> > Put(int id, TypeDTO type) { MessageType typeDb = (MessageType)type; if (typeDb == null) { return(BadRequest()); } using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { var typeDbLast = await serviceDbContext.MessageTypes.FindAsync(id); typeDbLast.MessageTemplate = type.Template; await serviceDbContext.SaveChangesAsync(); return(Ok(typeDbLast)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }
public async Task <ActionResult <MessageStatus> > Put(int id, StatusDTO status) { MessageStatus statusDb = (MessageStatus)status; if (statusDb == null) { return(BadRequest()); } using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { var statusDbLast = await serviceDbContext.MessageStatuses.FindAsync(id); statusDbLast.StatusName = status.Name; await serviceDbContext.SaveChangesAsync(); return(Ok(statusDbLast)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }
public async Task <ActionResult <Message> > Put(int id, MessageDTO messageRequest) { Message message = (Message)messageRequest; if (message == null) { return(BadRequest()); } using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { var dbMessage = await serviceDbContext.Messages.FindAsync(id); dbMessage.ReceiverId = messageRequest.ReceiverId; dbMessage.SendingDate = messageRequest.SendingDate; dbMessage.Status = messageRequest.Status; dbMessage.Port = messageRequest.Port; dbMessage.MessageType = messageRequest.Type; await serviceDbContext.SaveChangesAsync(); return(Ok(message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }
public async Task <ActionResult <Message> > Delete(int id) { using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { var mailingPort = await serviceDbContext.MailingPorts.FindAsync(id); serviceDbContext.MailingPorts.Remove(mailingPort); await serviceDbContext.SaveChangesAsync(); return(Ok(mailingPort)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }
public async Task <ActionResult <MailingPort> > Post(PortDTO port) { MailingPort mailingPort = (MailingPort)port; if (mailingPort == null) { return(BadRequest()); } using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { serviceDbContext.MailingPorts.Add(mailingPort); await serviceDbContext.SaveChangesAsync(); return(Ok(mailingPort)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }
public async Task <ActionResult <MessageStatus> > Post(TypeDTO type) { MessageType typeDb = (MessageType)type; if (typeDb == null) { return(BadRequest()); } using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { serviceDbContext.MessageTypes.Add(typeDb); await serviceDbContext.SaveChangesAsync(); return(Ok(typeDb)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }
public async Task <ActionResult <Message> > Post(MessageDTO messageRequest) { Message message = (Message)messageRequest; if (message == null) { return(BadRequest()); } using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext()) { try { serviceDbContext.Messages.Add(message); await serviceDbContext.SaveChangesAsync(); return(Ok(message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } }