Exemple #1
0
        public async Task <bool> Add(AddProductRequestModel model)
        {
            try
            {
                if (!model.IsNull())
                {
                    using (var uow = _unitOfWorkFactory.CreateUow())
                    {
                        uow.GetEntityRepository <Product>().Insert(new Product
                        {
                            Id          = Guid.NewGuid().ToString(),
                            MenuId      = model.MenuId,
                            Name        = model.Name,
                            Price       = model.Price,
                            Description = model.Description,
                            DateCreated = DateTime.Now.GetDate()
                        });

                        await uow.Commit();

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                _logger.LogTrace(e.StackTrace);
            }
            return(false);
        }
Exemple #2
0
        public async Task <GetCouponResponseModel> GetCouponByName(string name)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(name))
                {
                    using (var uow = _unitOfWorkFactory.CreateUow())
                    {
                        var coupons = (await uow.GetEntityRepository <Coupon>()
                                       .ItemsAsync(q => q.Name.Equals(name, StringComparison.CurrentCulture)))
                                      .FirstOrDefault();

                        if (!coupons.IsNull())
                        {
                            return new GetCouponResponseModel
                                   {
                                       Id       = coupons.Id,
                                       Discount = coupons.Discount,
                                       IsAvail  = coupons.IsUsed.Equals(CouponEnum.USED) ? false : true,
                                       IsValid  = DateTime.Now.GetDate() > coupons.Validity ? false : true
                                   }
                        }
                        ;
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                _logger.LogTrace(e.StackTrace);
            }
            return(default);
        public async Task <string> GetDefaultCustomer()
        {
            try
            {
                using (var uow = _unitOfWorkFactory.CreateUow())
                {
                    var customer = (await uow.GetEntityRepository <Customer>()
                                    .ItemsAsync())
                                   .FirstOrDefault();

                    if (!customer.IsNull())
                    {
                        return(customer.Id);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                _logger.LogTrace(e.StackTrace);
            }
            return(string.Empty);
        }
Exemple #4
0
        public async Task <IEnumerable <GetOrderResponseModel> > Get()
        {
            try
            {
                using (var uow = _unitOfWorkFactory.CreateUow())
                {
                    var orders = await uow.GetEntityRepository <Order>().ItemsAsync();

                    var customerOrders = await uow.GetEntityRepository <CustomerOrder>().ItemsWithAsync(null, q => q.Product);

                    if (orders.Any() &&
                        customerOrders.Any())
                    {
                        return(orders.OrderByDescending(o => o.OrderDate).Select(q => new GetOrderResponseModel
                        {
                            Id = q.Id,
                            OverallTotal = q.Total,
                            DiscountedTotal = q.DiscountedTotal,
                            OrderItems = customerOrders.Where(o => o.OrderRefId.Equals(q.RefId))
                                         .Select(o => new SaveOrderOrderItem
                            {
                                Name = o.Product.Name,
                                Qty = o.Qty,
                                Price = o.Product.Price,
                                Subtotal = o.Total
                            })
                        }));
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                _logger.LogTrace(e.StackTrace);
            }
            return(default);