Пример #1
0
        public ActionResult <VideoRequestDetailsForCustomerVM> Details(int id)
        {
            try
            {
                var          curUser = accountUtil.GetCurrentUser(User);
                VideoRequest request = VideoRequestService.GetActiveSingleDetailsWithRelatedDataByID(id);

                if (request == null || !VideoRequestService.BelongsToCustomer(request, curUser.ID))
                {
                    throw new Exception("Ваш заказ не найден");
                }

                if (request.ViewedByCustomer == false)
                {
                    request.ViewedByCustomer = true;
                    VideoRequestService.Update(request, curUser.ID);
                }

                var requestVM = new VideoRequestDetailsForCustomerVM(request);
                requestVM.edit_btn_is_available   = VideoRequestService.IsEditable(request);
                requestVM.cancel_btn_is_available = VideoRequestService.IsCancelable(request);

                //requestVM.request_price = VideoRequestPriceCalculationsService.CalculateRequestPrice(request);
                //requestVM.RequestPriceToStr();

                //requestVM.remaining_price = VideoRequestPriceCalculationsService.CalculateRemainingPrice(request.Price, request.WebsiteCommission);
                //requestVM.RemainingPriceToStr();

                requestVM.video_is_confirmed = VideoRequestService.IsVideoConfirmed(request);
                //requestVM.payment_screenshot_is_uploaded = VideoRequestService.IsPaymentScreenshotUploaded(request);

                //requestVM.payment_is_confirmed = VideoRequestService.IsPaymentConfirmed(request);
                if (requestVM.video_is_confirmed)
                {
                    //requestVM.video = new AttachmentDetailsVM(request.Video);
                    requestVM.video = AttachmentDetailsVM.ToVM(request.Video);
                }

                if (requestVM.edit_btn_is_available)
                {
                    requestVM.video_request_edit_vm = new VideoRequestEditVM(request);
                    requestVM.video_request_edit_vm.video_request_types = VideoRequestTypeService.GetAsSelectList();
                }

                //VideoRequestEditVM editModelVM = new VideoRequestEditVM(request);

                return(requestVM);
            }
            catch (Exception ex)
            {
                return(CustomBadRequest(ex));
            }
        }
Пример #2
0
        public ActionResult <VideoRequestDetailsForTalentVM> Details(int id)
        {
            try
            {
                var          curUser = accountUtil.GetCurrentUser(User);
                VideoRequest request = VideoRequestService.GetActiveSingleDetailsWithRelatedDataByID(id);

                if (request == null || !VideoRequestService.BelongsToTalent(request, curUser.ID))
                {
                    throw new Exception("Ваш заказ не найден");
                }

                if (request.ViewedByTalent == false)
                {
                    request.ViewedByTalent = true;
                    VideoRequestService.Update(request, curUser.ID);
                }

                VideoRequestDetailsForTalentVM requestVM = new VideoRequestDetailsForTalentVM(request);

                //requestVM.accept_btn_is_available = VideoRequestService.IsAcceptable(request);
                requestVM.cancel_btn_is_available = VideoRequestService.IsCancelable(request);

                //requestVM.request_price = VideoRequestPriceCalculationsService.CalculateRequestPrice(request);
                //requestVM.RequestPriceToStr();

                //requestVM.remaining_price = VideoRequestPriceCalculationsService.CalculateRemainingPrice(request.Price, request.WebsiteCommission);
                //requestVM.RemainingPriceToStr();

                return(requestVM);
            }
            catch (Exception ex)
            {
                return(CustomBadRequest(ex));
            }
        }
Пример #3
0
        public IActionResult Create([FromBody] VideoRequestCreateVM modelVM)
        {
            origin += "Create";
            TelegramBotService.SendMessage("Creating video request", origin);

            try
            {
                var curUser = accountUtil.GetCurrentUser(User);
                var talent  = TalentService.GetAvailableByID(modelVM.talent_id);

                if (AccountUtil.IsUserCustomer(curUser))
                {
                    if (ModelState.IsValid)
                    {
                        if (ValidateFromProperty(modelVM.from, modelVM.type_id))
                        {
                            if (talent != null)
                            {
                                if (talent.Price == modelVM.price)
                                {
                                    Invoice invoice = InvoiceService.GetByID(modelVM.invoice_id);
                                    if (invoice == null)
                                    {
                                        throw new Exception("Инвойс не найден");
                                    }

                                    PaymoService.ConfirmHold(invoice, modelVM.sms);
                                    InvoiceService.Update(invoice, curUser.ID);

                                    var curCustomer = CustomerService.GetByUserID(curUser.ID);

                                    VideoRequest model = modelVM.ToModel(curCustomer);

                                    try
                                    {
                                        //1. create model and send notification
                                        VideoRequestService.Add(model, invoice, curUser.ID);
                                    }
                                    catch (Exception ex)
                                    {
                                        PaymoService.CancelHold(invoice);
                                        InvoiceService.Update(invoice, curUser.ID);

                                        throw ex;
                                    }

                                    ////2. create hangfire RequestAnswerJobID and save it
                                    //newRequest.RequestAnswerJobID = HangfireService.CreateJobForVideoRequestAnswerDeadline(newRequest, curUser.ID);
                                    //create hangfire VideoJobID
                                    model.VideoJobID = HangfireService.CreateJobForVideoRequestVideoDeadline(model, curUser.ID);

                                    VideoRequestService.Update(model, curUser.ID);

                                    TelegramBotService.SendMessage("Video request successfully created", origin);
                                    return(Ok(new { id = model.ID }));
                                }
                                else
                                {
                                    throw new Exception("Пока вы заполняли форму, Талант успел изменить цену");
                                }
                            }
                            else
                            {
                                throw new Exception("Талант не существует либо временно недоступен");
                            }
                        }
                        else
                        {
                            throw new Exception("Укажите от кого");
                        }
                    }
                    else
                    {
                        throw new Exception("Указаны некорректные данные");
                    }
                }
                else
                {
                    throw new Exception("Таланты не могут заказывать видео. Зайдите как клиент");
                }
            }
            catch (Exception ex)
            {
                TelegramBotService.SendMessage(ex.Message, origin);
                return(CustomBadRequest(ex));
            }
        }