public async Task <ActionResult <UserDto> > Add(UserDto userDto)
        {
            var user = userDto.ToUser();

            db.Users.Add(user);
            await db.SaveChangesAsync();

            userDto = new UserDto(user);
            return(Ok(userDto));
        }
        public async Task <ActionResult <ContactDto> > Add(ContactDto contactDto)
        {
            var contact = contactDto.ToContact();

            db.Contacts.Add(contact);
            await db.SaveChangesAsync();

            contactDto = new ContactDto(contact);
            return(Ok(contactDto));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Add(OrderDto orderDto)
        {
            var order = orderDto.ToOrder();

            db.Orders.Add(order);
            await db.SaveChangesAsync();

            orderDto = new OrderDto(order);

            return(Ok(orderDto));
        }
        public async Task <ActionResult <List <BasicTicketDto> > > Add(Guid orderId, List <BasicTicketDto> basicTicketDtos)
        {
            var order = await db.Orders.Include(e => e.BasicTickets).FirstOrDefaultAsync(e => e.Id == orderId);

            if (order == null)
            {
                return(NotFound());
            }

            var basicTickets = new List <BasicTicket>();

            foreach (var basicTicketDto in basicTicketDtos)
            {
                var basicTicket = basicTicketDto.ToBasicTicket(db);
                basicTickets.Add(basicTicket);
                order.BasicTickets.Add(basicTicket);
            }
            await db.SaveChangesAsync();

            basicTicketDtos = basicTickets.Select(e => new BasicTicketDto(e)).ToList();

            return(Ok(basicTicketDtos));
        }