Beispiel #1
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));
            }
        }
Beispiel #2
0
        /// <summary>
        /// this method is used for cancelling both the REQUEST and VIDEO
        /// by both CUSTOMER and TALENT
        /// </summary>
        public void Cancel(VideoRequest model, string userID, string userType)
        {
            if (!BelongsToUser(model, userID))
            {
                throw new Exception("Вы обрабатываете не принадлежащий Вам заказ");
            }

            if (!IsCancelable(model))
            {
                throw new Exception("Текущий статус заказа не позволяет отменить его");
            }

            if (userType == UserTypesEnum.talent.ToString())
            {
                model.RequestStatusID = (int)VideoRequestStatusEnum.canceledByTalent;
                //model.DateVideoCanceledByTalent = DateTime.Now;
                model.DateRequestCanceledByTalent = DateTime.Now;

                model.ViewedByCustomer = false;
                model.ViewedByTalent   = true;
            }
            else
            {
                model.RequestStatusID = (int)VideoRequestStatusEnum.canceledByCustomer;
                //model.DateVideoCanceledByCustomer = DateTime.Now;
                model.DateRequestCanceledByCustomer = DateTime.Now;

                model.ViewedByCustomer = true;
                model.ViewedByTalent   = false;
            }

            //var invoice = InvoiceService.GetByID(model.InvoiceID.Value);
            PaymoService.CancelHold(model.Invoice);

            Update(model, userID);

            string title         = "";
            string body          = "";
            string adresatUserID = "";

            if (userType == UserTypesEnum.talent.ToString())
            {
                //TO-DO: send firebase notification to Customer
                title         = model.Talent.FullName;
                body          = "Талант отменил Ваш заказ";
                adresatUserID = model.Customer.UserID;
            }
            else
            {
                //TO-DO: send firebase notification to Talent
                title         = model.Customer.FullName;
                body          = "Клиент отменил Ваш заказ";
                adresatUserID = model.Talent.UserID;
            }

            Dictionary <string, string> data = new Dictionary <string, string>()
            {
                ["request_id"] = model.ID.ToString()
            };

            FirebaseRegistrationTokenService.SendNotification(adresatUserID, title, body, data);
        }