コード例 #1
0
        public async Task <ResponseModel <CustomerOrderDTO> > Create(CustomerOrderDTO customerOrderDTO)
        {
            try
            {
                foreach (var orderObj in customerOrderDTO.Orders)
                {
                    //Map customer orders view model to orders entity model
                    var order = new Order
                    {
                        CustomerID = customerOrderDTO.CustomerId,
                        Amount     = Convert.ToDecimal(orderObj.Amount),
                        OrderDate  = Convert.ToDateTime(orderObj.OrderDate)
                    };
                    _unitOfWork.OrderRepository.Add(order);
                }
                //commiting the transaction
                await _unitOfWork.CompleteAsync();

                return(new ResponseModel <CustomerOrderDTO>
                {
                    ResponseCode = Constants.OK, ResponseMessage = Constants.OK, ResponseData = customerOrderDTO
                });
            }
            catch (Exception)
            {
                return(new ResponseModel <CustomerOrderDTO>
                {
                    ResponseCode = Constants.Server_Error, ResponseMessage = Constants.Server_Error, ResponseData = null
                });
            }
        }
コード例 #2
0
 async Task NotifyOrder(CustomerOrderDTO order)
 {
     if (!(order.OrderStatus.Name == "1-Unpaid" ||
           order.OrderStatus.Name == "2-Paid"))
     {
         await App.SignalRService.Notify(order, $"{Constants.Customer}-{order.CustomerId}");
     }
 }
コード例 #3
0
 async Task NotifyOrder(CustomerOrderDTO order)
 {
     if (order.OrderStatus.Name == "1-Unpaid" ||
         order.OrderStatus.Name == "2-Paid")
     {
         await App.SignalRService.Notify(order, Constants.Employee);
     }
 }
コード例 #4
0
        public async Task LoadItem(CustomerOrderDTO item)
        {
            this.BindingContext = item;
            var list = await StoreWebApiClient.Instance.GetItems <OrderStatusDTO>("OrderStatuses");

            StatusPicker.ItemsSource        = list;
            StatusPicker.ItemDisplayBinding = new Binding("Name");
            StatusPicker.SelectedItem       = list.First(x => x.Id == item.OrderStatusId);
        }
コード例 #5
0
 public async Task Notify(CustomerOrderDTO order, string group)
 {
     try
     {
         await Connection.InvokeAsync(Constants.ServerMethod, order, group);
     }
     catch (Exception ex)
     {
     }
 }
コード例 #6
0
        public async Task <ApiResponse> PostOrder([FromBody] CustomerOrderDTO customerOrderDTO)
        {
            ResponseModel <CustomerOrderDTO> result;

            if (!ModelState.IsValid)
            {
                throw new ApiException(ModelState.AllErrors());
            }
            result = await _orderservice.Create(customerOrderDTO);

            return(ApiResponseFactory <CustomerOrderDTO> .GetResponse(result));
        }
コード例 #7
0
        public async void AddButton_Clicked(object sender, EventArgs e)
        {
            var item = new CustomerOrderDTO()
            {
                Id         = 0,
                Amount     = 0,
                Customer   = App.CurrentCustomer,
                CustomerId = App.CurrentCustomer.Id,
                Date       = DateTime.UtcNow
            };

            await Navigation.PushAsync(new CustomerOrderPage(item));
        }
コード例 #8
0
        public IHttpActionResult PostCustomerOrder(CustomerOrderDTO customerOrderDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CustomerOrder customerOrder = new CustomerOrder();

            customerOrder.AddressId  = customerOrderDTO.AddressId;
            customerOrder.CustomerId = customerOrderDTO.CustomerId;
            customerOrder.OrderDate  = DateTime.Now;


            db.SaveChanges();
            logger.Info(String.Format("CustomerOrder Created: ", customerOrder.OrderId));

            for (int i = 0; i < customerOrderDTO.OrderDetails.Count; i++)
            {
                customerOrder.OrderDetails.Add(new OrderDetail()
                {
                    ProductId = customerOrderDTO.OrderDetails[i].ProductId, Quantity = customerOrderDTO.OrderDetails[i].Quantity, OrderId = customerOrder.OrderId
                });
            }

            db.CustomerOrders.Add(customerOrder);

            try
            {
                db.SaveChanges();
                logger.Info(String.Format("OrderDetails created for CustomerOrder {0}: ", customerOrder.OrderId));
            }
            catch (DbUpdateException)
            {
                if (CustomerOrderExists(customerOrder.OrderId))
                {
                    logger.Error(String.Format("Customer Order order exists OrderId {0}: ", customerOrder.OrderId));
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = customerOrder.OrderId }, customerOrder));
        }
コード例 #9
0
        public CustomerOrderDTO GetCustomerOrderByCustomerId(int customerId)
        {
            var customerOrder = _customerOrder.GetOrderByCustomerId(customerId);

            var customerOrderView = new CustomerOrderDTO()
            {
                Name        = customerOrder.Name,
                CustomerId  = customerOrder.CustomerId,
                Country     = customerOrder.Country,
                DateOfBirth = customerOrder.DateOfBirth,
                OrderId     = customerOrder.OrderId,
                Amount      = customerOrder.Amount,
                VAT         = customerOrder.VAT
            };

            return(customerOrderView);
        }
コード例 #10
0
        public async Task LoadItem(CustomerOrderDTO item)
        {
            this.BindingContext = item;
            var list = await StoreWebApiClient.Instance.GetItems <OrderStatusDTO>("OrderStatuses");

            if (item.Id == 0)
            {
                this.ToolbarItems.RemoveAt(1);

                var unpaidStatus = list.First(x => x.Name == "1-Unpaid");
                item.OrderStatusId = unpaidStatus.Id;
                item.OrderStatus   = unpaidStatus;
            }

            StatusPicker.ItemsSource        = list;
            StatusPicker.ItemDisplayBinding = new Binding("Name");
            StatusPicker.SelectedItem       = list.First(x => x.Id == item.OrderStatusId);
        }
コード例 #11
0
        public async Task <IActionResult> PostCustomerOrder([FromBody] CustomerOrderDTO customerOrder)
        {
            customerOrder.OrderDetail = null;
            customerOrder.OrderStatus = null;
            customerOrder.Customer    = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var co = Mapper.Map <CustomerOrder>(customerOrder);

            _context.CustomerOrder.Add(co);
            await _context.SaveChangesAsync();

            customerOrder.Id = co.Id;

            return(CreatedAtAction("GetCustomerOrder", new { id = co.Id }, customerOrder));
        }
コード例 #12
0
        public void GetCustomerOrderById_ShouldGet_IfExists_NegativeTest()
        {
            // Arrange
            int customerId       = 1;
            int orderId          = 5;
            var custName         = "Percy L";
            var customerOrderDTO = new CustomerOrderDTO
            {
                CustomerId = customerId,
                OrderId    = orderId
            };

            _customerOrderMock.Setup(x => x.GetOrderByCustomerId(customerId)).Returns(customerOrderDTO);

            // Act
            var customerOrder = _customerOrderContext.GetOrderByCustomerId(customerId);

            // Assert
            Assert.Equal(expected: customerId, actual: customerOrder.CustomerId);
            Assert.Equal(expected: custName, actual: customerOrder.Name);
        }
コード例 #13
0
        CustomerOrderDTO ICustomerOrder.GetOrderByCustomerId(int customerId)
        {
            try
            {
                var customerOrder = _context.Customers.Include(o => o.Orders).Where(x => x.CustomerId == customerId).FirstOrDefault();

                var custOrd = new CustomerOrderDTO()
                {
                    Name        = customerOrder.Name,
                    Country     = customerOrder.Country,
                    CustomerId  = customerOrder.CustomerId,
                    DateOfBirth = customerOrder.DateOfBirth,
                    OrderId     = customerOrder.Orders.FirstOrDefault().OrderId,
                    Amount      = customerOrder.Orders.FirstOrDefault().Amount,
                    VAT         = customerOrder.Orders.FirstOrDefault().VAT
                };

                return(custOrd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #14
0
        public async Task <IActionResult> PutCustomerOrder([FromRoute] int id, [FromBody] CustomerOrderDTO customerOrder)
        {
            customerOrder.OrderDetail = null;
            customerOrder.OrderStatus = null;
            customerOrder.Customer    = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customerOrder.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Mapper.Map <CustomerOrder>(customerOrder)).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerOrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #15
0
 public static void Notify(CustomerOrderDTO order, string message)
 {
     CrossLocalNotifications.Current.Show("Store Notification", message);
 }
コード例 #16
0
 public void NotifyEmployee(CustomerOrderDTO order)
 {
     StoreNotification.Notify(order, $"An order has a new status: {order.OrderStatus.Name}. Please review it.");
 }
コード例 #17
0
 public static void CustomerDTOAddARow(CustomerOrderDTO customerOrderDTO)
 {
     Persistence.Repositories.CustomerOrderRepository.CustomerDTOAddARow(customerOrderDTO);
 }
コード例 #18
0
 public void NotifyCustomer(CustomerOrderDTO order)
 {
     StoreNotification.Notify(order, $"An employee has updated your oder with the status: {order.OrderStatus.Name}.");
 }
コード例 #19
0
        public IHttpActionResult PutCustomerOrder(int id, CustomerOrderDTO customerOrderDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customerOrderDTO.OrderId)
            {
                return(BadRequest());
            }

            CustomerOrder customerOrder = db.CustomerOrders.Find(id);

            // Adres Guncelle
            if (db.CustomerAddresses.Find(customerOrderDTO.AddressId).CustomerId != customerOrder.CustomerId)
            {
                return(BadRequest());
            }

            customerOrder.AddressId = customerOrderDTO.AddressId;
            db.SaveChanges();

            // Silinecekler
            var silinecekIdler = customerOrder.OrderDetails.Select(od => od.ProductId).Except(customerOrderDTO.OrderDetails.Select(oddto => oddto.ProductId));
            var silinecekler   = customerOrder.OrderDetails.Where(od => silinecekIdler.Contains(od.ProductId));

            db.OrderDetails.RemoveRange(silinecekler);

            // Adet Duzenlemeleri
            foreach (var orderDetail in customerOrder.OrderDetails)
            {
                orderDetail.Quantity = customerOrderDTO.OrderDetails.First(oddto => oddto.ProductId == orderDetail.ProductId).Quantity;
            }

            // Eklenecekler
            var eklenecekIdler = customerOrderDTO.OrderDetails.Select(oddto => oddto.ProductId).Except(customerOrder.OrderDetails.Select(od => od.ProductId));
            var eklenecekler   = customerOrderDTO.OrderDetails.Where(oddto => eklenecekIdler.Contains(oddto.ProductId));

            for (int i = 0; i < eklenecekler.Count(); i++)
            {
                customerOrder.OrderDetails.Add(new OrderDetail()
                {
                    ProductId = eklenecekler.ElementAt(i).ProductId, Quantity = eklenecekler.ElementAt(i).Quantity, OrderId = customerOrder.OrderId
                });
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                logger.Error(String.Format("CustomerOrder {0} Update Error: DbUpdateConcurrencyException: " + ex.Message, customerOrderDTO.OrderId));
                if (!CustomerOrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                logger.Error(String.Format("CustomerOrder {0}  Update Error:DbUpdateConcurrencyException: " + ex.Message, customerOrderDTO.OrderId));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #20
0
 public CustomerOrderPage(CustomerOrderDTO item)
 {
     InitializeComponent();
     LoadItem(item);
 }