// Owner can be changed. public DTOs.Order Update(int id, DTOs.Order order) { Order existingOrder = Get(id); if (order.Status != null) { existingOrder.Status = _decodesQueryProcessor.Get <OrderStatusDecode>(order.Status); } if (order.Field != null) { existingOrder.Field = _fieldsQueryProcessor.Get(order.Field.Id ?? 0); } if (order.PlayersNumber != 0) { existingOrder.PlayersNumber = order.PlayersNumber; } existingOrder.StartDate = DateUtils.ConvertFromJavaScript(order.StartDate); Update(id, existingOrder); return(new DTOs.Order().Initialize(existingOrder)); }
public DTOs.Order Get(int id) { DTOs.Order order = _ordersQueryProcessor.GetOrder(id); order.Participants = _participantsQueryProcessor.Search(null, null, new int?[] { (int)Consts.Decodes.InvitationStatus.Sent, (int)Consts.Decodes.InvitationStatus.Accepted }, null, order.Id, null, null, null, null).ToList(); return(order); }
public async Task <IActionResult> PostInvoice([FromBody] DTOs.Order invoice) { //_context.Invoices.Add(invoice); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetInvoice", new { id = invoice.Id }, invoice); // Console.WriteLine("demo" + invoice.Email + invoice.order_item); var ins = new Invoice(); ins.Name = invoice.Name; ins.IdCustomer = invoice.IdCustomer; ins.TotalMoney = invoice.TotalMoney; ins.CreateAt = invoice.CreateAt; ins.CustomerAddress = invoice.CustomerAddress; ins.Phone = invoice.Phone; ins.Email = invoice.Email; _context.Invoices.Add(ins); var result = await _context.SaveChangesAsync(); long id = ins.Id; foreach (var item in invoice.order_item) { var insd = new InvoiceDetail(); insd.IdInvoice = id; insd.IdProduct = (long)item.IdProduct; insd.Amount = (long)item.Amount; insd.Price = (double)item.Price; _context.InvoiceDetails.Add(insd); await _context.SaveChangesAsync(); } return(Ok(new { status = true, data = ins })); }
public DTOs.Order Save([FromBody] DTOs.Order order) { var currPrincipal = HttpContext.Current.User as ClaimsPrincipal; var currIdentity = currPrincipal.Identity as BasicAuthenticationIdentity; int userId = currIdentity.UserId; return(_ordersQueryProcessor.Save(order)); }
public override Participant Initialize(Domain.Participant domain) { Id = domain.Id; Date = domain.Date; Order = new DTOs.Order().Initialize(domain.Order); Status = domain.Status.Id; return(this); }
public DTOs.Order Update([FromUri] int id, [FromBody] DTOs.Order order) { if (order.Status == (int)Consts.Decodes.OrderStatus.Canceled) { if (order.Participants != null) { foreach (var participant in order.Participants) { participant.Status = (int)Consts.Decodes.InvitationStatus.Rejected; _participantsQueryProcessor.Update(participant.Id ?? 0, participant); } } } return(_ordersQueryProcessor.Update(id, order)); }
public DTOs.Order Save(DTOs.Order order) { // TODO remove EndDate from Order Order newOrder = new Order() { StartDate = DateUtils.ConvertFromJavaScript(order.StartDate), Field = _fieldsQueryProcessor.Get(order.Field.Id ?? 0), PlayersNumber = order.PlayersNumber, Status = _decodesQueryProcessor.Get <OrderStatusDecode>(order.Status), Participants = new List <Participant>() }; Order persistedOrder = Save(newOrder); return(new DTOs.Order().Initialize(persistedOrder)); }
public ActionResult AddNewOrder([FromBody] DTOs.Order newOrder) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var orderId = Guid.NewGuid(); newOrder.Id = orderId; newOrder.Created = DateTime.UtcNow; try { Datastore.TryAdd(orderId, newOrder); } catch (Exception e) { string message = "We could not add the new order."; Log.Error(message + $" Reason: {0}", e); throw new OrderServiceException(message); } // TODO: Retry & exception handling using (var bus = RabbitHutch.CreateBus(_settings.RabbitMqConnectionString)) { var identity = User.Identity as ClaimsIdentity; var subjectId = identity?.Claims.FirstOrDefault(c => c.Type == "sub")?.Value; var message = new NewOrderMessage { UserId = subjectId, Order = Mapper.Map <Order>(newOrder) }; // TODO: Exception handling bus.Publish(message); _orderHubContext.Clients.Group(message.UserId).SendAsync("orderCreated"); } return(Ok()); }
public List <DTOs.Order> SearchOptionalsOrders(int?orderId = null, int?fieldId = null, int?fieldType = null, DateTime?date = null) { DateTime?dateTime = date.Value.Date; //if (date.HasValue) // dateTime = DateUtils.ConvertFromJavaScript(date ?? 0); List <DTOs.Order> optionals = _ordersQueryProcessor.SearchOptionalOrders(fieldId, null, fieldType, dateTime ?? DateTime.Today); if (orderId.HasValue) { DTOs.Order current = _ordersQueryProcessor.GetOrder(orderId ?? 0); if (current.Field.Id == fieldId && DateUtils.ConvertFromJavaScript(current.StartDate).Date == dateTime.Value.Date) { optionals.Add(current); } } return(optionals); }
public void AddNewOrder([FromBody] DTOs.Order newOrder) { var orderId = Guid.NewGuid(); newOrder.Id = orderId; try { Datastore.TryAdd(orderId, newOrder); } catch (Exception e) { string message = "We could not add the new order."; //Log.Error(message + $" Reason: {0}", e); throw new OrderServiceException(message); } // TODO: Retry & exception handling using (var bus = RabbitHutch.CreateBus(_settings.RabbitMqConnectionString)) { var identity = User.Identity as ClaimsIdentity; var subjectId = identity?.Claims.FirstOrDefault(c => c.Type == "sub")?.Value; var message = new QueuingMessages.NewOrderMessage { UserId = subjectId, Order = Mapper.Map <QueuingMessages.Order>(newOrder) }; // TODO: Exception handling bus.Publish(message); _orderHubContext.Clients.Group(message.UserId).InvokeAsync("orderCreated"); } }
// PUT: api/Order/5 edits an order public void Put(int id, [FromBody] DTOs.Order order) { orderrepository.UpdateOrder(order, id); }
// POST: api/Order creates an new order public void Post([FromBody] DTOs.Order order) { orderrepository.CreateOrder(order); }