示例#1
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);
        }