Пример #1
0
        public void OrderTheOrder(string bookingToken, IList <OrderlineDto> orderLines)
        {
            var bookingtype = bookingToken.StartsWith("CB") ? OrderTypeEnum.CommonBooking : OrderTypeEnum.GuestBooking;
            var booking     = GetBooking(bookingToken);

            if (booking == null)
            {
                throw new Exception("No booking");
            }
            var orders = UoW.Repository <Order>().GetAll(o => o.IdReservation == booking.Id || o.IdInvitationGuest == booking.Id);
            var order  = orders != null?orders.FirstOrDefault() : new Order();

            switch (bookingtype)
            {
            case OrderTypeEnum.CommonBooking:

                order = new Order {
                    IdReservation = booking.Id
                };
                break;

            case OrderTypeEnum.GuestBooking:
                order = new Order {
                    IdInvitationGuest = booking.Id
                };
                break;
            }
            UoW.Repository <Order>().Create(order);
            UoW.Commit();

            var orderLinesList = CreateOrderLines(order.Id, orderLines);

            CreateOrderExtraIngredient(orderLinesList);
        }
Пример #2
0
        /// <summary>
        /// PLease use this method as an example of how to use pagination
        /// </summary>
        /// <param name="isFav"></param>
        /// <param name="maxPrice"></param>
        /// <param name="minLikes"></param>
        /// <param name="searchBy"></param>
        /// <param name="categoryIdList"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <List <DishDtoResult> > GetDishListFromFilter(bool isFav, decimal maxPrice, int minLikes, string searchBy, IList <long> categoryIdList, long userId)
        {
            var includeList = new List <string> {
                "DishCategory", "DishCategory.IdCategoryNavigation", "DishIngredient", "DishIngredient.IdIngredientNavigation", "IdImageNavigation"
            };
            var dishPredicate = PredicateBuilder.True <Dish>();

            if (!string.IsNullOrEmpty(searchBy))
            {
                var criteria = searchBy.ToLower();
                dishPredicate = dishPredicate.And(d => d.Name.ToLower().Contains(criteria) || d.Description.ToLower().Contains(criteria));
            }
            if (maxPrice > 0)
            {
                dishPredicate = dishPredicate.And(d => d.Price <= maxPrice);
            }

            if (categoryIdList.Any())
            {
                dishPredicate = dishPredicate.And(r => r.DishCategory.Any(a => categoryIdList.Contains(a.IdCategory)));
            }
            if (isFav && userId >= 0)
            {
                var favourites = await UoW.Repository <UserFavourite>().GetAllAsync(w => w.IdUser == userId);

                var dishes = favourites.Select(s => s.IdDish);
                dishPredicate = dishPredicate.And(r => dishes.Contains(r.Id));
            }

            var result = await UoW.Repository <Dish>().GetAllIncludeAsync(includeList, dishPredicate);

            return(Mapper.Map <List <DishDtoResult> >(result));
        }
Пример #3
0
        private List <OrderDishExtraIngredient> CreateOrderLinesExtras(ref List <OrderLine> OrderLineList, IList <OrderlineDto> OrderlineDtoList)
        {
            var result = new List <OrderDishExtraIngredient>();

            try
            {
                foreach (var orderLine in OrderLineList)
                {
                    var item = OrderlineDtoList.FirstOrDefault(l => l.orderLine.dishId == orderLine.IdDish &&
                                                               l.orderLine.amount == orderLine.Amount && l.orderLine.comment == orderLine.Comment).extras.
                               Select(e =>
                    {
                        var c = new OrderDishExtraIngredient
                        {
                            IdIngredient = e.id,
                            IdOrderLine  = orderLine.Id.Value
                        };

                        UoW.Repository <OrderDishExtraIngredient>().Create(c);

                        return(c);
                    });
                    result.AddRange(item);
                }
                UoW.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} : {ex.InnerException}");
                throw ex;
            }

            return(result);
        }
Пример #4
0
        public EmailResponseDto AcceptOrRejectInvitationGuest(string bookingToken, bool accepted)
        {
            var invitedGuest = UoW.Repository <InvitedGuest>().Get(i => i.GuestToken == bookingToken);

            if (invitedGuest == null)
            {
                return(null);
            }
            invitedGuest.ModificationDate = DateTime.UtcNow.ToLocalTime();
            invitedGuest.Accepted         = accepted;

            UoW.Commit();

            return(new EmailResponseDto
            {
                id = invitedGuest.Id,
                revision = null,
                modificationCounter = 0,
                guestToken = invitedGuest.GuestToken,
                accepted = invitedGuest.Accepted.Value,
                modificationDate = invitedGuest.ModificationDate,
                bookingId = invitedGuest.IdBooking,
                email = invitedGuest.Email
            });
        }
Пример #5
0
        private Booking CreateReservation(int bookingDtoType, string reservationDtoName, int reservationAssistants, string reservationDtoEmail, DateTime reservationDtoDate,
                                          long?userId)
        {
            var bookingTypeStringToken = bookingDtoType == 0
                ? BookingTypeConst.CommonBooking
                : BookingTypeConst.GuestBooking;

            var reservation = new Booking
            {
                Name             = reservationDtoName,
                IdBookingType    = bookingDtoType,
                BookingDate      = Convert.ToDateTime(reservationDtoDate),
                Canceled         = false,
                CreationDate     = DateTime.Now,
                UserId           = userId,
                ReservationToken = GetReservationToken(bookingTypeStringToken, reservationDtoEmail),
                Assistants       = reservationAssistants,
                ExpirationDate   = Convert.ToDateTime(reservationDtoDate).AddHours(-1),
                Email            = reservationDtoEmail
            };

            UoW.Repository <Booking>().Create(reservation);
            UoW.Commit();
            return(reservation);
        }
Пример #6
0
        private async Task <List <InvitedGuest> > GetInvitedFromToken(string token)
        {
            var includeList = new List <string>
            {
                "IdBookingNavigation", "IdBookingNavigation.Order", "Order.OrderLine.IdDishNavigation", "Order.OrderLine.IdOrderNavigation", "Order.OrderLine.OrderDishExtraIngredient", "Order.OrderLine.OrderDishExtraIngredient.IdIngredientNavigation"
            };

            return((string.IsNullOrEmpty(token)
                ? await UoW.Repository <InvitedGuest>().GetAllIncludeAsync(includeList)
                : await UoW.Repository <InvitedGuest>().GetAllIncludeAsync(includeList, o => o.GuestToken.ToLower().Contains(token.ToLower()))) as List <InvitedGuest>);
        }
Пример #7
0
        public EmailResponseDto AcceptOrRejectInvitationGuest(string bookingToken, bool accepted)
        {

            var invitedGuest = UoW.Repository<InvitedGuest>().Get(i => i.GuestToken == bookingToken);
            if (invitedGuest == null) return null;
            invitedGuest.ModificationDate = DateTime.UtcNow.ToLocalTime();
            invitedGuest.Accepted = accepted;

            UoW.Commit();

            return Mapper.Map<EmailResponseDto>(invitedGuest);
        }
Пример #8
0
        private void DeleteOrder(long idOrder)
        {
            if (idOrder <= 0)
            {
                return;
            }

            var orderLinesToDelete = UoW.Repository <OrderLine>().GetAll(o => o.IdOrder == idOrder);

            orderLinesToDelete.Select(o => { UoW.Repository <OrderLine>().Delete(o); return(o); });
            UoW.Repository <Order>().Delete(p => p.Id == idOrder);
        }
Пример #9
0
        public async Task <List <Dish> > GetDishListFromFilter(bool isFav, decimal maxPrice, int minLikes, string searchBy, IList <long> categoryIdList, long userId)
        {
            var includeList = new List <string>
            {
                "DishCategory", "DishCategory.IdCategoryNavigation", "DishIngredient", "DishIngredient.IdIngredientNavigation", "IdImageNavigation"
            };

            var result = await UoW.Repository <Dish>().GetAllIncludeAsync(includeList);

            if (isFav && userId >= 0)
            {
                //var dishes =  result;
                if (result != null)
                {
                    var favourites = result.SelectMany(f => f.UserFavourite).Select(f => f.Id).ToList();
                    if (favourites.Any())
                    {
                        result = result.Where(r => favourites.Contains(r.Id)).ToList();
                    }
                }
            }

            if (categoryIdList.Any())
            {
                result = result.Where(r => r.DishCategory.Any(a => categoryIdList.Contains(a.IdCategory))).ToList();
            }

            if (!string.IsNullOrEmpty(searchBy))
            {
                var criteria = searchBy.ToLower();
                result = result.Where(d => d.Name.ToLower().Contains(criteria) || d.Description.ToLower().Contains(criteria)).ToList();
            }

            //todo twitter
            if (minLikes > 0)
            {
            }

            if (maxPrice > 0)
            {
                result = result.Where(r => r.Price <= maxPrice).ToList();
            }

            var c = result.ToList();

            //PopulateDishReferences(ref c);

            return(result.ToList());
        }
Пример #10
0
 private void CreateOrderExtraIngredient(IList <KeyValuePair <OrderLine, List <Extra> > > orderLinesItems)
 {
     foreach (var orderLine in orderLinesItems)
     {
         foreach (var extra in orderLine.Value)
         {
             UoW.Repository <OrderDishExtraIngredient>().Create(new OrderDishExtraIngredient
             {
                 IdIngredient = extra.id,
                 IdOrderLine  = orderLine.Key.Id
             });
         }
     }
     UoW.Commit();
 }
Пример #11
0
        private async Task<PaginationResult<Booking>> GetBookingListPaged(int currentpage, int pageSize, string bookingToken, List<string> includeList)
        {
            var result = new PaginationResult<Booking>();
            var bookingtype = GetType(bookingToken);
            switch (bookingtype)
            {
                case OrderTypeEnum.CommonBooking:
                    result = await UoW.Repository<Booking>().GetAllpagedAsync(currentpage, pageSize,b => b.ReservationToken == bookingToken);
                    break;
                case OrderTypeEnum.GuestBooking:
                    var idBookingList = await UoW.Repository<InvitedGuest>().GetAllpagedAsync(currentpage, pageSize, i => i.GuestToken == bookingToken);                   
                    ((List<Booking>)result.Results).AddRange(idBookingList.Results.Select(idBooking => UoW.Repository<Booking>().GetAllInclude(includeList, b => b.Id == idBooking.IdBooking).FirstOrDefault()));                    
                    break;
            }

            return result;
        }
Пример #12
0
        private List<Booking> GetBookingList(string bookingToken, List<string> includeList)
        {
            var result = new List<Booking>();
            var bookingtype = GetType(bookingToken);
            switch (bookingtype)
            {
                case OrderTypeEnum.CommonBooking:
                    result = UoW.Repository<Booking>().GetAll(b => b.ReservationToken == bookingToken).ToList();
                    break;
                case OrderTypeEnum.GuestBooking:
                    var idBookingList = UoW.Repository<InvitedGuest>().GetAll(i => i.GuestToken == bookingToken);
                    result.AddRange(idBookingList.Select(idBooking => UoW.Repository<Booking>().GetAllInclude(includeList, b => b.Id == idBooking.IdBooking).FirstOrDefault()));
                    break;
            }

            return result;
        }
Пример #13
0
        public async Task<bool> CancelBooking(string token)
        {

            try
            {
                var booking = await UoW.Repository<Booking>().GetAsync(b => b.ReservationToken == token);
                if (booking == null) return false;
                booking.Canceled = true;

                UoW.Commit();
                return true;
            }
            catch (Exception ex)
            {
                var msg = $"{ex.Message} : {ex.InnerException}";
                Console.WriteLine(msg);
            }
            return false;
        }
Пример #14
0
        private List <OrderLine> CreateOrderLines(long orderId, IList <OrderlineDto> orderLines)
        {
            try
            {
                var orderLinesMap = Mapper.Map <List <OrderLine> >(orderLines).Select(c =>
                {
                    c.IdOrder = orderId;
                    c.OrderDishExtraIngredient = new List <OrderDishExtraIngredient>();
                    c = UoW.Repository <OrderLine>().Create(c);
                    UoW.Commit();
                    return(c);
                });

                return(orderLinesMap.ToList());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} : {ex.InnerException}");
                throw ex;
            }
        }
Пример #15
0
        private Order CreateOrder(string bookingToken)
        {
            var order = new Order();

            try
            {
                var booking = GetBooking(bookingToken);
                if (booking == null)
                {
                    throw new Exception("No booking");
                }

                var bookingtype = bookingToken.StartsWith("CB") ? OrderTypeEnum.CommonBooking : OrderTypeEnum.GuestBooking;
                var orders      = UoW.Repository <Order>().GetAll(o => o.IdReservation == booking.Id || o.IdInvitationGuest == booking.Id);

                if (orders != null && orders.Count > 0)
                {
                    throw new Exception("The order already exists");
                }
                else
                {
                    order = bookingtype == OrderTypeEnum.CommonBooking ? new Order {
                        IdReservation = booking.Id
                    }
                } : new Order {
                    IdInvitationGuest = booking.Id
                };;

                order = UoW.Repository <Order>().Create(order);

                UoW.Commit();

                return(order);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} : {ex.InnerException}");
                throw ex;
            }
        }
Пример #16
0
        private List <InvitedGuest> CreateInvitationGuests(long bookingId, IList <string> guestList, string userEmail)
        {
            var result = new List <InvitedGuest>();

            foreach (var mail in guestList.Distinct())
            {
                var item = new InvitedGuest()
                {
                    IdBooking        = bookingId,
                    Email            = mail,
                    Accepted         = null,
                    ModificationDate = DateTime.Now,
                    GuestToken       = GetReservationToken(BookingTypeConst.GuestBooking, userEmail)
                };

                UoW.Repository <InvitedGuest>().Create(item);
                result.Add(item);
            }
            UoW.Commit();

            return(result);
        }
Пример #17
0
        public async Task <List <OrderSearchFullResponseDto> > GetBookinSearchFullResponse(string bookingToken, string email)
        {
            var result      = new List <OrderSearchFullResponseDto>();
            var includeList = new List <string>
            {
                "Order", "Order.OrderLine", "Order.OrderLine.IdDishNavigation", "Order.OrderLine.IdOrderNavigation", "Order.OrderLine.OrderDishExtraIngredient", "Order.OrderLine.OrderDishExtraIngredient.IdIngredientNavigation", "InvitedGuest", "User", "Table"
            };

            try
            {
                #region orders from common booking
                //search through common booking
                var commonbookingList = UoW.Repository <Booking>().GetAllInclude(includeList, b => b.IdBookingType == 0);
                foreach (var booking in commonbookingList)
                {
                    result.AddRange(GetOrderSearchFullResponseDtoList(booking, booking.Order));
                }
                #endregion

                #region orders from invited guest
                //search through invited
                var invitedList = await GetInvitedFromToken(bookingToken);

                foreach (var invitedItem in invitedList)
                {
                    result.AddRange(GetOrderSearchFullResponseDtoList(invitedItem.IdBookingNavigation, invitedItem.Order));
                }
                #endregion
            }
            catch (Exception ex)
            {
                var msg = $"{ex.Message} : {ex.InnerException}";
            }

            return(result);
        }
Пример #18
0
        private List <KeyValuePair <OrderLine, List <Extra> > > CreateOrderLines(long orderId, IList <OrderlineDto> orderLines)
        {
            var result = new List <KeyValuePair <OrderLine, List <Extra> > >();

            foreach (var orderItem in orderLines)
            {
                var orderline = new OrderLine
                {
                    IdOrder = orderId,
                    Amount  = orderItem.orderLine.amount,
                    IdDish  = orderItem.orderLine.dishId,
                    Comment = orderItem.orderLine.comment
                };

                UoW.Repository <OrderLine>().Create(orderline);
                if (orderItem.extras.Any())
                {
                    result.Add(new KeyValuePair <OrderLine, List <Extra> >(orderline, orderItem.extras.ToList()));
                }
            }

            UoW.Commit();
            return(result);
        }
Пример #19
0
 public AuthorService(IUnitOfWork <AlejandriaContext> unitOfWork) : base(unitOfWork)
 {
     _authorRepository     = UoW.Repository <IAuthorRepository, Author>();
     _bookRepository       = UoW.Repository <IBookRepository, Book>();
     _authorBookRepository = UoW.Repository <IAuthorBookRepository, AuthorBook>();
 }
Пример #20
0
        public IEnumerable <OrderDetailsDTO> GetOrderDetailsBy(int orderID)
        {
            var order = UoW.Repository <Order>().Query().GetChildEntities(ord => ord.OrderID == orderID);

            return(Mapper.Map <IEnumerable <OrderDetailsDTO> >(order.Order_Details));
        }
Пример #21
0
 public IEnumerable <OrdersDTO> GetAllOrders()
 {
     return(Mapper.Map <IEnumerable <OrdersDTO> >(UoW.Repository <Order>().Query().GetAll()));
 }
Пример #22
0
 public void DeleteOrder(int OrderID)
 {
     UoW.Repository <Order>().Remove(OrderID);
 }
Пример #23
0
 public void DeleteOrder(OrdersDTO order)
 {
     UoW.Repository <Order>().Remove(Mapper.Map <Order>(order));
 }
Пример #24
0
 public void AddOrder(OrdersDTO order)
 {
     UoW.Repository <Order>().Add(Mapper.Map <Order>(order));
 }
 public void UpdateProduct(ProductsDTO updproduct)
 {
     UoW.Repository <Product>().Update(Mapper.Map <Product>(updproduct));
 }
 public void DeleteProduct(int productID)
 {
     UoW.Repository <Product>().Remove(productID);
     UoW.Save(saveChanges);
 }
 public void DeleteProduct(ProductsDTO product)
 {
     UoW.Repository <Product>().Remove(Mapper.Map <ProductsDTO, Product>(product));
 }
 public ProductsDTO GetProductBy(int id)
 {
     return(Mapper.Map <ProductsDTO>(UoW.Repository <Product>().Get(id)));
 }
 public IEnumerable <ProductsDTO> GetAllProducts(int Unitsleft)
 {
     return(Mapper.Map <IEnumerable <ProductsDTO> >(UoW.Repository <Product>().Find(prd => prd.UnitsInStock == Unitsleft)));
 }
 public IEnumerable <ProductsDTO> GetAllProducts()
 {
     return(Mapper.Map <IEnumerable <ProductsDTO> >(UoW.Repository <Product>().Query().GetAll()));
 }