Ejemplo n.º 1
0
        public ServiceResult <TDto> AddProductToOrderTable <TDto>(long orderTableID, long productID, decimal quantity)
        {
            var product = ProductRepository.GetByID(productID);

            if (product == null)
            {
                return(ServiceResult <TDto> .CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            var order = Repository.Get(x => x.OrderTables.Any(y => y.ID == orderTableID));

            if (order == null)
            {
                return(ServiceResult <TDto> .CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            var orderTable = order.OrderTables.First(y => y.ID == orderTableID);

            orderTable.OrderDetails.Add(new OrderDetail
            {
                Quantity    = quantity,
                Product     = product,
                OrderStatus = SmsCache.BranchConfigs.Current.UseKitchenFunction ? OrderStatus.Ordered : OrderStatus.Done
            });
            Repository.Save(order);

            return(ServiceResult <TDto> .CreateSuccessResult(Mapper.Map <TDto>(orderTable)));
        }
Ejemplo n.º 2
0
        public ServiceResult <TDto> UpdateOrderedProductStatus <TDto>(long orderDetailID, OrderStatus value)
        {
            var order = Repository.Get(x => x.OrderTables.Any(y => y.OrderDetails.Any(z => z.ID == orderDetailID)));

            if (order == null)
            {
                return(ServiceResult <TDto> .CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            var orderTable  = order.OrderTables.First(y => y.OrderDetails.Any(z => z.ID == orderDetailID));
            var orderDetail = orderTable.OrderDetails.First(z => z.ID == orderDetailID);

            orderDetail.OrderStatus = value;
            Repository.Save(order);

            if (orderDetail.OrderStatus == OrderStatus.KitchenRejected)
            {
                RejectRepository.Save(new Reject
                {
                    BranchID       = SmsCache.UserContext.CurrentBranchId,
                    ProductCode    = orderDetail.Product.ProductCode,
                    ProductVNName  = orderDetail.Product.VNName,
                    ProductENName  = orderDetail.Product.ENName,
                    Quantity       = orderDetail.Quantity,
                    UnitVNName     = orderDetail.Product.Unit.VNName,
                    UnitENName     = orderDetail.Product.Unit.ENName,
                    OrderComment   = orderDetail.Comment,
                    KitchenComment = orderDetail.KitchenComment,
                    CreatedDate    = DateTime.Now,
                    CreatedUser    = SmsCache.UserContext.UserName
                });
            }

            return(ServiceResult <TDto> .CreateSuccessResult(Mapper.Map <TDto>(orderDetail)));
        }
Ejemplo n.º 3
0
        public ServiceResult DeleteByOrderTableID(long orderTableID)
        {
            var order = Repository.Get(x => x.OrderTables.Select(y => y.ID).Contains(orderTableID));

            return(order == null
                ? ServiceResult.CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business))
                : ServiceResult.CreateResult(Repository.Delete(order.ID)));
        }
Ejemplo n.º 4
0
        public ServiceResult <UploadedFileDto> GetByPhysicalPath(string physicalPath)
        {
            var result = Repository.Get(x => x.PhysicalPath.ToLower() == physicalPath.ToLower());

            return(result == null
                ? ServiceResult <UploadedFileDto> .CreateFailResult()
                : ServiceResult <UploadedFileDto> .CreateSuccessResult(Mapper.Map <UploadedFileDto>(result)));
        }
Ejemplo n.º 5
0
        public virtual ServiceResult DeleteInCurrentBranch(long primaryKey)
        {
            var result = Repository.DeleteInCurrentBranch(primaryKey);

            return(result
                ? ServiceResult.CreateSuccessResult()
                : ServiceResult.CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
        }
Ejemplo n.º 6
0
        public virtual ServiceResult <TModel> GetByIDInCurrentBranch <TModel>(long primaryKey)
        {
            var result = Repository.GetByIDInCurrentBranch(primaryKey);

            return(result == null
               ? ServiceResult <TModel> .CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business))
               : ServiceResult <TModel> .CreateSuccessResult(Mapper.Map <TModel>(result)));
        }
Ejemplo n.º 7
0
        public ServiceResult UpdateUserSystem(UserDto user)
        {
            if (Repository.Exists(x => x.Username == user.Username))
            {
                return(ServiceResult.CreateFailResult());
            }

            Repository.SaveUserSystem(Mapper.Map <User>(user));

            return(ServiceResult.CreateSuccessResult());
        }
Ejemplo n.º 8
0
        public ServiceResult Payment(long orderID, string taxInfo, decimal tax, decimal serviceFee, PaymentMethod paymentMethod)
        {
            var order = Repository.GetByID(orderID);

            if (order == null)
            {
                return(ServiceResult.CreateFailResult());
            }

            InvoiceRepository.CreateInvoice(order, SmsCache.UserContext.UserID, SmsCache.BranchConfigs.Current.Currency, tax, serviceFee, taxInfo, paymentMethod);

            order.OrderProgressStatus = OrderProgressStatus.Done;
            Repository.Save(order);

            return(ServiceResult.CreateSuccessResult());
        }
Ejemplo n.º 9
0
        public ServiceResult DeleteOrderDetail(long orderDetailID)
        {
            var order = Repository.Get(x => x.OrderTables.Any(y => y.OrderDetails.Any(z => z.ID == orderDetailID)));

            if (order == null)
            {
                return(ServiceResult.CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            var orderTable  = order.OrderTables.First(y => y.OrderDetails.Any(z => z.ID == orderDetailID));
            var orderDetail = orderTable.OrderDetails.First(z => z.ID == orderDetailID);

            orderTable.OrderDetails.Remove(orderDetail);

            return(ServiceResult.CreateSuccessResult());
        }
Ejemplo n.º 10
0
        public ServiceResult MoveTable(long orderTableID, long tableID)
        {
            var order = Repository.Get(x => x.OrderTables.Select(y => y.ID).Contains(orderTableID));

            if (order == null)
            {
                return(ServiceResult.CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            order.OrderTables.First(x => x.ID == orderTableID).Table = new Table {
                ID = tableID
            };
            Repository.Save(order);

            return(ServiceResult.CreateSuccessResult());
        }
Ejemplo n.º 11
0
        public ServiceResult <TModel> Get <TModel>(string username, string password)
        {
            var user = Repository.Get(x => x.Username == username && x.Password == EncryptionHelper.SHA256Hash(password));

            if (user == null)
            {
                return(ServiceResult <TModel> .CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Login_UsernamePasswordInvalid), ErrorType.Business)));
            }

            if (user.IsLockedOut)
            {
                return(ServiceResult <TModel> .CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Login_UserLocked), ErrorType.Business)));
            }

            return(ServiceResult <TModel> .CreateSuccessResult(Mapper.Map <TModel>(user)));
        }
Ejemplo n.º 12
0
        public ServiceResult UpdateProductToOrderTable(long orderDetailID, string columnName, string value)
        {
            var order = Repository.Get(x => x.OrderTables.Any(y => y.OrderDetails.Any(z => z.ID == orderDetailID)));

            if (order == null)
            {
                return(ServiceResult.CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            var orderTable  = order.OrderTables.First(y => y.OrderDetails.Any(z => z.ID == orderDetailID));
            var orderDetail = orderTable.OrderDetails.First(z => z.ID == orderDetailID);

            if (orderDetail == null)
            {
                return(ServiceResult.CreateFailResult());
            }

            switch (columnName)
            {
            case "qty":
                if (orderDetail.OrderStatus != OrderStatus.KitchenAccepted)
                {
                    orderDetail.Quantity = decimal.Parse(value);
                }
                break;

            case "cmt":
                orderDetail.Comment = value;
                break;

            case "discount":
            {
                orderDetail.Discount        = decimal.Parse(value);
                orderDetail.DiscountCode    = "";
                orderDetail.DiscountType    = DiscountType.Number;
                orderDetail.DiscountComment = "";
                break;
            }

            case "kitchenComment":
                orderDetail.KitchenComment = value;
                break;
            }
            Repository.Save(order);

            return(ServiceResult.CreateSuccessResult());
        }
Ejemplo n.º 13
0
        public ServiceResult SendToKitchen(long orderTableID)
        {
            var order = Repository.Get(x => x.OrderTables.Any(y => y.ID == orderTableID));

            if (order == null)
            {
                return(ServiceResult.CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            var orderTable = order.OrderTables.First(y => y.ID == orderTableID);

            foreach (var orderDetail in orderTable.OrderDetails.Where(x => x.OrderStatus == OrderStatus.Ordered || x.OrderStatus == OrderStatus.KitchenRejected))
            {
                orderDetail.OrderStatus = OrderStatus.SentToKitchen;
            }

            Repository.Save(order);

            return(ServiceResult.CreateSuccessResult());
        }
Ejemplo n.º 14
0
        public ServiceResult ChangeCustomer(long orderID, long customerID, string customerName, string address, string cellPhone, string dob)
        {
            var order = Repository.GetByID(orderID);

            if (order == null)
            {
                return(ServiceResult.CreateFailResult());
            }

            if (customerID > 0)
            {
                order.Customer = new Customer {
                    ID = customerID
                };
                order.CustomerName = String.Empty;
                order.Address      = String.Empty;
                order.CellPhone    = String.Empty;
                order.DOB          = null;
            }
            else
            {
                order.Customer     = null;
                order.CustomerName = customerName;
                order.Address      = address;
                order.CellPhone    = cellPhone;
                if (dob.Trim() != "")
                {
                    order.DOB = DateTime.Parse(dob);
                }
                else
                {
                    order.DOB = null;
                }
            }
            Repository.Save(order);
            return(ServiceResult.CreateSuccessResult());
        }
Ejemplo n.º 15
0
        public ServiceResult Save(List <PageLabelDto> pageLabels)
        {
            if (!pageLabels.Any())
            {
                return(ServiceResult.CreateFailResult(new Error(SmsCache.Message.Get(ConstMessageIds.Business_DataNotExist), ErrorType.Business)));
            }

            var pageID   = pageLabels[0].Page.ID;
            var labelIds = pageLabels.ConvertAll(x => x.LabelID);

            var labels = Repository
                         .List(x => x.Page.ID == pageID && labelIds.Contains(x.LabelID) && x.BranchID == SmsCache.UserContext.CurrentBranchId)
                         .ToList();

            var pages = PageRepository.ListAll();

            pageLabels.ForEach(x =>
            {
                var oldLabel = labels.FirstOrDefault(y => y.LabelID == x.LabelID);
                if (oldLabel != null)
                {
                    x.ID = oldLabel.ID;
                }

                var label      = Mapper.Map <PageLabel>(x);
                label.BranchID = SmsCache.UserContext.CurrentBranchId;
                label.Page     = pages.FirstOrDefault(p => p.ID == x.Page.ID);

                if (label.Page == null)
                {
                    return;
                }
                Repository.Save(label);
            });

            return(ServiceResult.CreateSuccessResult());
        }