コード例 #1
0
    public async Task <ActionResult> Post([FromBody] EmailSenderDTO sender)
    {
        if (sender == null)
        {
            return(await Task.Run(() => BadRequest()));
        }

        sender.Created = DateTime.Now;

        var _sender = _mapper.Map <EmailSender>(sender);

        _context.EmailSenders.Add(_sender);
        _context.SaveChanges();

        sender = _mapper.Map <EmailSenderDTO>(_sender);
        return(await Task.Run(() => new ObjectResult(sender)));
    }
コード例 #2
0
    public async Task <ActionResult> Put(int id, [FromBody] EmailSenderDTO sender)
    {
        if (sender == null)
        {
            return(await Task.Run(() => BadRequest()));
        }

        var orgSender = _context.EmailSenders
                        .SingleOrDefault(e => e.Id == id);

        if (orgSender == null)
        {
            return(await Task.Run(() => NotFound()));
        }

        orgSender = _mapper.Map(sender, orgSender);
        _context.SaveChanges();

        return(await Task.Run(() => new ObjectResult(sender)));
    }