Exemplo n.º 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));
            }
        }
Exemplo n.º 2
0
        public IActionResult Edit(int id, [FromBody] VideoRequestEditVM modelVM)
        {
            try
            {
                var curUser = accountUtil.GetCurrentUser(User);

                VideoRequest request = VideoRequestService.GetActiveSingleDetailsWithRelatedDataByID(id);
                if (request == null || !VideoRequestService.BelongsToCustomer(request, curUser.ID))
                {
                    //return NotFound();
                    throw new Exception("Заказ не найден");
                }

                if (!VideoRequestService.IsEditable(request))
                {
                    throw new Exception("Данный запрос нельзя редактировать");
                }

                if (ModelState.IsValid)
                {
                    if (ValidateFromProperty(modelVM.from, modelVM.type_id))
                    {
                        try
                        {
                            modelVM.UpdateModel(request);

                            VideoRequestService.Edit(request, curUser.ID);

                            return(Ok());
                        }
                        catch (Exception ex)
                        {
                            //ModelState.AddModelError("", ex.Message);
                            return(CustomBadRequest(ex));
                        }
                    }
                    else
                    {
                        //ModelState.AddModelError("From", "Укажите от кого");
                        throw new Exception("Укажите от кого");
                    }
                }
                else
                {
                    //ModelState.AddModelError("", "Указаны некорректные данные");
                    throw new Exception("Указаны некорректные данные");
                }
            }
            catch (Exception ex)
            {
                return(CustomBadRequest(ex));
            }
        }