Exemplo n.º 1
0
        public async Task <bool> SetCancelOrder(int id)
        {
            var result = false;

            var checkProcessStatusExist = await _placedOrderProcessStatusBusiness.CheckProcessStatusExist(_authenticationDto.RestaurantId,
                                                                                                          _authenticationDto.BranchId, id, (int)EOrderProcess.CanceledOrder);

            if (!checkProcessStatusExist)
            {
                var processStatus = new PlacedOrderProcessStatus()
                {
                    RestaurantId   = _authenticationDto.RestaurantId,
                    BranchId       = _authenticationDto.BranchId,
                    PlacedOrderId  = id,
                    OrderProcessId = (int)EOrderProcess.CanceledOrder,
                    Status         = 1,
                    CreatedStaffId = _authenticationDto.UserId,
                    CreatedDate    = DateTime.Now
                };
                var lastProcessStatus = await _placedOrderProcessStatusBusiness.Add(processStatus);

                if (lastProcessStatus != null)
                {
                    result = true;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <bool> SetCompleteOrder(PlacedOrder model)
        {
            var result  = false;
            var process = 0;

            if (model.OrderTypeId == (int)EOrderType.DineIn)
            {
                process = (int)EOrderProcess.ServingOrder;
            }
            else if (model.OrderTypeId == (int)EOrderType.Delivery || model.OrderTypeId == (int)EOrderType.ToGo)
            {
                process = (int)EOrderProcess.AvailableOrder;
            }
            var processStatus = new PlacedOrderProcessStatus()
            {
                RestaurantId   = _authenticationDto.RestaurantId,
                BranchId       = _authenticationDto.BranchId,
                PlacedOrderId  = model.Id,
                OrderProcessId = process,
                Status         = 1,
                CreatedStaffId = _authenticationDto.UserId,
                CreatedDate    = DateTime.Now
            };
            var lastProcessStatus = await _placedOrderProcessStatusBusiness.Add(processStatus);

            if (lastProcessStatus != null)
            {
                result = true;
            }

            return(result);
        }
        public async Task <PlacedOrderProcessStatus> Add(PlacedOrderProcessStatus model)
        {
            var entity = _placedOrderProcessStatusRepository.Add(model);

            if (entity != null)
            {
                var placedOrder = new PlacedOrder()
                {
                    RestaurantId   = entity.RestaurantId,
                    BranchId       = entity.BranchId,
                    Id             = entity.PlacedOrderId,
                    OrderProcessId = entity.OrderProcessId
                };

                // Update Order Process to Placed Order
                var result = await UpdateOrderProcess(placedOrder);

                if (result)
                {
                    await _placedOrderProcessStatusRepository.SaveChangeAsync();

                    return(model);
                }
            }
            return(null);
        }
        public async Task <bool> SetFinishOrder(PlacedOrder model, Checkout checkout)
        {
            var result = false;
            var record = await _placedOrderRepository.Repo.FirstOrDefaultAsync(c => c.Id == model.Id);

            if (record != null)
            {
                record.TaxId          = model.TaxId;
                record.Tax            = model.Tax;
                record.DiscountType   = model.DiscountType;
                record.Discount       = model.Discount;
                record.Description    = model.Description;
                record.IsFinish       = 1;
                record.UpdatedStaffId = model.UpdatedStaffId;
                record.UpdatedDate    = DateTime.Now;

                if (record.DiscountType == (int)EDiscountType.Percent)
                {
                    record.FinalPrice = record.Price + record.Tax - ((record.Price * record.Discount) / 100);
                }
                else if (record.DiscountType == (int)EDiscountType.Money)
                {
                    record.FinalPrice = record.Price + record.Tax - record.Discount;
                }

                //modified checkout model
                //if ReceivedAmount = 0, it mean no adding record to Checkout table
                if (checkout.ReceivedAmount > 0)
                {
                    checkout.RestaurantId   = record.RestaurantId;
                    checkout.BranchId       = record.BranchId;
                    checkout.PlacedOrderId  = record.Id;
                    checkout.Amount         = record.FinalPrice;
                    checkout.CreatedStaffId = record.UpdatedStaffId;
                    checkout.CreatedDate    = DateTime.Now;

                    _checkoutRepository.Add(checkout);
                }

                //Add new process status
                var processStatus = new PlacedOrderProcessStatus()
                {
                    RestaurantId   = record.RestaurantId,
                    BranchId       = record.BranchId,
                    PlacedOrderId  = record.Id,
                    OrderProcessId = (int)EOrderProcess.PaidOrder,
                    Status         = 1,
                    CreatedStaffId = record.UpdatedStaffId,
                    CreatedDate    = DateTime.Now
                };
                _placedOrderProcessStatusRepository.Add(processStatus);

                await _unitOfWork.SaveChangesAsync();

                result = true;
            }
            return(result);
        }
Exemplo n.º 5
0
        public async Task <PlacedOrderDto> Post(PlacedOrder model)
        {
            PlacedOrderDto result = null;

            //if current user is Restaurant Admin, don't let them create order
            // because when update price will be wrong
            if (_authenticationDto.TypeId == (int)EAccountType.Admin || _authenticationDto.TypeId == (int)EAccountType.Mod ||
                _authenticationDto.TypeId == (int)EAccountType.RestaurantAdmin)
            {
                return(result);
            }

            if (ModelState.IsValid)
            {
                if (model.Tax == null)
                {
                    model.Tax = 0;
                }
                if (model.DiscountType == null)
                {
                    model.DiscountType = (int)EDiscountType.Money;
                }
                if (model.Discount == null)
                {
                    model.Discount = 0;
                }
                model.RestaurantId   = _authenticationDto.RestaurantId;
                model.BranchId       = _authenticationDto.BranchId;
                model.OutputTypeId   = (int)EOutputType.Order;
                model.OrderTime      = DateTime.Now;
                model.CreatedDate    = DateTime.Now;
                model.CreatedStaffId = _authenticationDto.UserId;
                model.Status         = 1;
                var modelInsert = await _placedOrderBusiness.Add(model);

                result = modelInsert;

                // add order process as a record
                // Waiting Order Status
                if (result != null)
                {
                    var processStatus = new PlacedOrderProcessStatus()
                    {
                        RestaurantId   = modelInsert.RestaurantId,
                        BranchId       = modelInsert.BranchId,
                        PlacedOrderId  = modelInsert.Id,
                        OrderProcessId = (int)EOrderProcess.WaitingOrder,
                        Status         = 1,
                        CreatedStaffId = _authenticationDto.UserId,
                        CreatedDate    = DateTime.Now
                    };
                    var lastProcessStatus = await _placedOrderProcessStatusBusiness.Add(processStatus);
                }
            }
            return(result);
        }
        public async Task <PlacedOrderDetail> SetFinishOrderDetail(int id, int isFinish)
        {
            //if current user is Restaurant Admin, don't let them update order detail
            // because when update price will be wrong
            if (_authenticationDto.TypeId == (int)EAccountType.Admin || _authenticationDto.TypeId == (int)EAccountType.Mod ||
                _authenticationDto.TypeId == (int)EAccountType.RestaurantAdmin)
            {
                return(null);
            }

            var result = await _placedOrderDetailBusiness.SetFinishOrderDetail(_authenticationDto.RestaurantId, _authenticationDto.BranchId,
                                                                               id, isFinish);

            if (result != null)
            {
                var checkProcessStatusExist = await _placedOrderProcessStatusBusiness.CheckProcessStatusExist(_authenticationDto.RestaurantId,
                                                                                                              _authenticationDto.BranchId, result.PlacedOrderId, (int)EOrderProcess.PreparingOrder);

                if (!checkProcessStatusExist)
                {
                    var processStatus = new PlacedOrderProcessStatus()
                    {
                        RestaurantId   = result.RestaurantId,
                        BranchId       = result.BranchId,
                        PlacedOrderId  = result.PlacedOrderId,
                        OrderProcessId = (int)EOrderProcess.PreparingOrder,
                        Status         = 1,
                        CreatedStaffId = _authenticationDto.UserId,
                        CreatedDate    = DateTime.Now
                    };
                    var lastProcessStatus = await _placedOrderProcessStatusBusiness.Add(processStatus);
                }
            }

            return(result);
        }