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)); } }