public async Task <ActionResult> OrderPreview(List <string> idBrigade, double Total, int idPaymentState, int idStatusOrder, int?idAdmin, int?idTeamLead)
        {
            CreateOrderView createOrderView = new CreateOrderView();

            int idOrder = 0;

            if (idStatusOrder == (int)StatusOrder.Completed && idBrigade == null)
            {
                TempData.Keep("CreateOrder");

                return(RedirectToAction("OrderPreview", "TireChangeService", new RouteValueDictionary(new
                {
                    Error = true
                })));
            }

            if (TempData.ContainsKey("CreateOrder"))
            {
                createOrderView = (CreateOrderView)TempData["CreateOrder"];

                double priceListTireFittingAdditionalsSum = 0;

                if (createOrderView.priceListTireFittingAdditionals != null)
                {
                    priceListTireFittingAdditionalsSum = createOrderView.priceListTireFittingAdditionals.Sum(x => x.TheCost).Value;
                }

                if (createOrderView.numberOfTires != 0 || createOrderView.priceListTireFittings != null)
                {
                    double TotalSum = SumTireChangeService(createOrderView.priceListTireFittings, createOrderView.numberOfTires.Value) + priceListTireFittingAdditionalsSum;
                    idOrder = await _createOrder.SaveOrderTireFitting(TotalSum, Total, idPaymentState, idStatusOrder, createOrderView.client.Value, 4);
                }
                else if (priceListTireFittingAdditionalsSum != 0)
                {
                    idOrder = await _createOrder.SaveOrderTireFitting(priceListTireFittingAdditionalsSum, Total, idPaymentState, idStatusOrder, createOrderView.client, 4);
                }

                if (createOrderView.priceListTireFittingAdditionals != null)
                {
                    List <PriceListTireFittingAdditionalServicesBll> priceListTireFittings = new List <PriceListTireFittingAdditionalServicesBll>();
                    priceListTireFittings = Mapper.Map <List <PriceListTireFittingAdditionalServicesView>, List <PriceListTireFittingAdditionalServicesBll> >(createOrderView.priceListTireFittingAdditionals);

                    await _createOrder.SeveTireService(createOrderView.client, idOrder, priceListTireFittings);
                }

                if (createOrderView.priceListTireFittings != null)
                {
                    List <PriceListTireFittingBll> listTireFittingBlls = new List <PriceListTireFittingBll>();
                    listTireFittingBlls = Mapper.Map <List <PriceListTireFittingView>, List <PriceListTireFittingBll> >(createOrderView.priceListTireFittings);

                    await _createOrder.SaveTireChangeService(idOrder, createOrderView.numberOfTires.Value, listTireFittingBlls);
                }

                var order = await _orderServices.GetId(idOrder);

                if (idBrigade != null)
                {
                    // Начисление заработной платы сотрудникам
                    await _wageModules.Payroll(order, _wageModules.ConvertListToIEnumerable(idBrigade), (int)TypeService.TireFitting);
                }

                if (idAdmin != null)
                {
                    // Начисление заработной платы Администраору
                    await _wageModules.AdminWage(order, (int)TypeService.Sales, idAdmin.Value);
                }

                if (idTeamLead != null)
                {
                    // Наичление заработной платы Тим лидеру
                    await _wageModules.AdminWage(order, (int)TypeService.TireFitting, idTeamLead.Value);
                }

                TempData.Remove("CreateOrder");

                return(RedirectToAction("../Order/Index"));
            }

            TempData.Keep("CreateOrder");

            return(View());
        }
Esempio n. 2
0
        public async Task <ActionResult> ReviewTireStorageOrder(double?sum, int?idPaymentState, int?idStatusOrder, int?StockNumber)
        {
            if (StockNumber != null)
            {
                if (TempData.ContainsKey("TireStorageOrder") && TempData.ContainsKey("ReviwOrderMode"))
                {
                    var pageCreateResult  = TempData["TireStorageOrder"] as OrderTireStorageModelView;
                    var reviwOrderModules = TempData["ReviwOrderMode"] as ReviwOrderModelView;

                    OrderTireStorageModelBll orderTireStorage = Mapper.Map <OrderTireStorageModelView, OrderTireStorageModelBll>(pageCreateResult);
                    ReviwOrderModelBll       orderModelBll    = Mapper.Map <ReviwOrderModelView, ReviwOrderModelBll>(reviwOrderModules);

                    int idOrder = await _createOrder.SaveOrderTireFitting(reviwOrderModules.priceOfTire, reviwOrderModules.priceOfTire, idPaymentState.Value, idStatusOrder.Value, orderTireStorage.ClientId.Value, 5);

                    int idStorageFee = await _order.CreateStorageFee(orderTireStorage.storageTime.Value, sum);

                    if (reviwOrderModules.priceSilicone != 0 || reviwOrderModules.priceWheelWash != 0)
                    {
                        idOrderServices = await _createOrder.SaveOrderTireFitting(sum.Value, sum.Value, idPaymentState.Value, 1, orderTireStorage.ClientId.Value, 2);

                        if (reviwOrderModules.priceSilicone != 0)
                        {
                            var AdditionalTireStorageServicesEntity = new AdditionalTireStorageServicesView
                            {
                                clientsOfCarWashId     = orderTireStorage.ClientId.Value,
                                orderServicesCarWashId = idOrderServices.Value,
                                tireStorageServicesd   = orderModelBll.IdpriceSilicone,
                                Price = orderModelBll.priceSilicone
                            };

                            await _additionalTireStorageServices.Insert(TransformAnEntity(AdditionalTireStorageServicesEntity));
                        }

                        if (reviwOrderModules.priceWheelWash != 0)
                        {
                            var AdditionalTireStorageServicesEntity = new AdditionalTireStorageServicesView
                            {
                                clientsOfCarWashId     = orderTireStorage.ClientId.Value,
                                orderServicesCarWashId = idOrderServices.Value,
                                tireStorageServicesd   = orderModelBll.IdWheelWash,
                                Price = orderModelBll.priceWheelWash
                            };

                            await _additionalTireStorageServices.Insert(TransformAnEntity(AdditionalTireStorageServicesEntity));
                        }
                    }

                    var tireStorage = new TireStorageBll
                    {
                        serviceCostTirePackages = orderModelBll.priceNumberOfPackets,
                        dateOfAdoption          = orderTireStorage.dateOfAdoption,
                        quantity               = orderTireStorage.quantity,
                        radius                 = orderTireStorage.radius,
                        firm                   = orderTireStorage.firm,
                        discAvailability       = orderTireStorage.discAvailability,
                        storageFeeId           = idStorageFee,
                        tireStorageBags        = orderTireStorage.tireStorageBags,
                        wheelWash              = orderTireStorage.wheelWash,
                        IdOrderServicesCarWash = idOrder,
                        silicone               = orderTireStorage.silicone,
                        RelatedOrders          = idOrderServices,
                        stockNumber            = StockNumber
                    };

                    await _tireStorage.Insert(tireStorage);

                    await _wage.AdminWageTireStorage(idOrder, pageCreateResult.quantity.Value);
                }

                return(RedirectToAction("OrderTireStorage", "Order", new RouteValueDictionary(new
                {
                    typeOfOrder = 5,
                    statusOrder = 5
                })));
            }
            else
            {
                if (TempData.ContainsKey("Client"))
                {
                    TempData.Keep("Client");
                }

                if (TempData.ContainsKey("TireStorageOrder"))
                {
                    TempData.Keep("TireStorageOrder");
                }

                TempData.Keep("ReviwOrderMode");

                return(RedirectToAction("ReviewTireStorageOrder"));
            }
        }