Esempio n. 1
0
        private async Task UpdateOrderDeliveryAddress(OrderDeliveryAddress editOrderDeliveryAddress)
        {
            var EditOrderDeliveryAddress = await _context.OrderDeliveryAddresses
                                           .FindAsync(editOrderDeliveryAddress.OrderId);

            EditOrderDeliveryAddress.City       = editOrderDeliveryAddress.City;
            EditOrderDeliveryAddress.Floor      = editOrderDeliveryAddress.Floor;
            EditOrderDeliveryAddress.Address    = editOrderDeliveryAddress.Address;
            EditOrderDeliveryAddress.PostalCode = editOrderDeliveryAddress.PostalCode;

            _context.OrderDeliveryAddresses.Update(EditOrderDeliveryAddress);
            await _context.SaveChangesAsync();
        }
        public IHttpActionResult CreateOrderDeliveryAddress([FromBody] DeliveryAddress deliveryAddress)
        {
            try
            {
                OrderDeliveryAddress orderDeliveryAddress = null;

                long cartId = 0;

                ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;

                long.TryParse(principal.Claims.Where(c => c.Type == "participant_Id").Single().Value, out this.participantId);

                var validation = deliveryAddress.ValidationAddress();

                if (!string.IsNullOrEmpty(validation))
                {
                    return(BadRequest(validation));
                }

                var cart = this._cartService.Get(this.participantId);

                var deliveryAddressResult = this._cartService.Get(this.participantId, cart.Id);

                if (deliveryAddressResult.Id > 0)
                {
                    orderDeliveryAddress               = deliveryAddress.MappingDomain();
                    orderDeliveryAddress.Id            = deliveryAddressResult.Id;
                    orderDeliveryAddress.ParticipantId = this.participantId;
                    orderDeliveryAddress.CartId        = cart.Id;

                    orderDeliveryAddress = this._cartService.Add(orderDeliveryAddress);
                }
                else
                {
                    orderDeliveryAddress = deliveryAddress.MappingDomain();
                    orderDeliveryAddress.ParticipantId = this.participantId;
                    orderDeliveryAddress.CartId        = cart.Id;

                    orderDeliveryAddress = this._cartService.Add(orderDeliveryAddress);
                }


                cartId = cart.Id;

                return(Ok(cartId));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Esempio n. 3
0
        public async Task EditOrder(Order editOrder, OrderBy editOrderBy, OrderDeliveryAddress editOrderDeliveryAddress, List <OrderItem> addOrderItems)
        {
            var EditOrder = await _context.Orders.FindAsync(editOrder.OrderId);

            editOrderBy.OrderId          = EditOrder.OrderId;
            EditOrder.RecievingTime      = editOrder.RecievingTime;
            EditOrder.OrderCode          = editOrder.OrderCode;
            EditOrder.Remarks            = editOrder.Remarks;
            EditOrder.TotalBill          = editOrder.TotalBill;
            EditOrder.PaymentMethod      = editOrder.PaymentMethod;
            EditOrder.IsPaymentConfirmed = editOrder.IsPaymentConfirmed;
            EditOrder.OrderStatus        = editOrder.OrderStatus;
            EditOrder.IsCompleted        = editOrder.IsCompleted;


            _context.Orders.Update(EditOrder);
            await _context.SaveChangesAsync();
        }
Esempio n. 4
0
        public OrderDeliveryAddress MappingDomain()
        {
            var deliveryAddress = new OrderDeliveryAddress();

            deliveryAddress.Name       = this.Name;
            deliveryAddress.Street     = this.Street;
            deliveryAddress.Number     = this.Number;
            deliveryAddress.Complement = this.Complement;
            deliveryAddress.District   = this.District;
            deliveryAddress.City       = this.City;
            deliveryAddress.State      = this.State;
            deliveryAddress.ZipCode    = this.ZipCode;
            deliveryAddress.Reference  = this.Reference;
            deliveryAddress.Email      = this.Email;
            deliveryAddress.HomePhone  = this.HomePhone;
            deliveryAddress.CellPhone  = this.CellPhone;

            return(deliveryAddress);
        }
        public IHttpActionResult CreateOrderDeliveryAddress(long cartId)
        {
            try
            {
                OrderDeliveryAddress orderDeliveryAddress = null;

                DeliveryAddress deliveryAddress = null;

                ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;

                long.TryParse(principal.Claims.Where(c => c.Type == "participant_Id").Single().Value, out this.participantId);

                var deliveryAddressResult = this._cartService.Get(this.participantId, cartId);

                if (deliveryAddressResult != null && deliveryAddressResult.Id > 0)
                {
                    deliveryAddress = new DeliveryAddress(deliveryAddressResult);
                }
                else
                {
                    TicketGames.API.Models.Participant.Participant participant = null;

                    var key = string.Concat("Participant:Id:", participantId.ToString(), ":Register");

                    participant = CacheManager.GetObject <TicketGames.API.Models.Participant.Participant>(key);

                    if (participant == null)
                    {
                        var result = this._participantService.GetParticipant(participantId);

                        participant = new TicketGames.API.Models.Participant.Participant(result);
                    }

                    deliveryAddress = new DeliveryAddress(participant);
                }

                return(Ok(deliveryAddress));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Esempio n. 6
0
        public async Task AddOrder(Order addOrder, OrderBy addOrderBy, OrderDeliveryAddress addOrderDeliveryAddress, List <OrderItem> addOrderItems)
        {
            await _context.Orders.AddAsync(addOrder);

            await _context.SaveChangesAsync();

            var OrderId = _context.Orders.Max(x => x.OrderId);

            addOrderBy.OrderId = OrderId;
            addOrderDeliveryAddress.OrderId = OrderId;
            foreach (var item in addOrderItems)
            {
                item.OrderId = OrderId;
            }

            await AddOrderBy(addOrderBy);
            await AddOrderDeliveryAddress(addOrderDeliveryAddress);
            await AddOrderItem(addOrderItems);
        }
        public OrderDeliveryAddress Create(OrderDeliveryAddress orderDeliveryAddress)
        {
            OrderDeliveryAddress deliveryAddressModified = null;

            if (orderDeliveryAddress.Id > 0)
            {
                using (var connect = new MySqlConnection(connection))
                {
                    //connect.Open();

                    string query = @"Select A.* From Tb_OrderDeliveryAddress A Inner Join Tb_Cart C On(A.CartId = C.Id) Where A.Id = @orderDeliveryAddressId And C.CartStatusId = 2;";

                    deliveryAddressModified = connect.Query <OrderDeliveryAddress>(query, new { orderDeliveryAddressId = orderDeliveryAddress.Id }).FirstOrDefault();

                    //connect.Close();
                }

                deliveryAddressModified.Name       = orderDeliveryAddress.Name;
                deliveryAddressModified.Street     = orderDeliveryAddress.Street;
                deliveryAddressModified.Number     = orderDeliveryAddress.Number;
                deliveryAddressModified.Complement = orderDeliveryAddress.Complement;
                deliveryAddressModified.District   = orderDeliveryAddress.District;
                deliveryAddressModified.City       = orderDeliveryAddress.City;
                deliveryAddressModified.State      = orderDeliveryAddress.State;
                deliveryAddressModified.Reference  = orderDeliveryAddress.Reference;
                deliveryAddressModified.ZipCode    = orderDeliveryAddress.ZipCode;
                deliveryAddressModified.Email      = orderDeliveryAddress.Email;
                deliveryAddressModified.CellPhone  = orderDeliveryAddress.CellPhone;
                deliveryAddressModified.HomePhone  = orderDeliveryAddress.HomePhone;

                this._context.Entry(deliveryAddressModified).State = EntityState.Modified;
            }
            else
            {
                deliveryAddressModified = this._context.Set <OrderDeliveryAddress>().Add(orderDeliveryAddress);
            }

            this._context.SaveChanges();

            return(deliveryAddressModified);
        }
        public bool UpdateOrderDeliveryAddressByCartId(long cartId, long orderId)
        {
            var orderDeliveryAddressModified = new OrderDeliveryAddress();

            using (var connect = new MySqlConnection(connection))
            {
                //connect.Open();

                string queryOrderDeliveryAddress = @"Select * From Tb_OrderDeliveryAddress Where CartId = @cartId;";

                orderDeliveryAddressModified = connect.Query <OrderDeliveryAddress>(queryOrderDeliveryAddress, new { cartId = cartId }).FirstOrDefault();

                //connect.Close();
            }

            orderDeliveryAddressModified.OrderId = orderId;

            this._context.Entry(orderDeliveryAddressModified).State = EntityState.Modified;

            return(this._context.SaveChanges() > 0);
        }
Esempio n. 9
0
 public OrderDeliveryAddress Add(OrderDeliveryAddress orderDeliveryAddress)
 {
     return(this._cartRepository.Create(orderDeliveryAddress));
 }
Esempio n. 10
0
        private async Task AddOrderDeliveryAddress(OrderDeliveryAddress addOrderDeliveryAddress)
        {
            await _context.OrderDeliveryAddresses.AddAsync(addOrderDeliveryAddress);

            await _context.SaveChangesAsync();
        }