示例#1
0
        public async Task SaveDecisionWithNullDecisionViewMode()
        {
            DecisionWrapper    decisionWrapper         = null;
            DecisionController documentationController = CreateDocumentationController;

            JsonResult jsonResult = await documentationController.SaveDecision(decisionWrapper);

            bool actual = jsonResult.Value.ToString().Contains("False");

            Assert.True(actual);
        }
示例#2
0
        public async Task <JsonResult> SaveDecision(DecisionWrapper decisionWrapper)
        {
            try
            {
                ModelState.Remove("DecisionWrapper.Decision.DecisionStatusType");
                if (!ModelState.IsValid && decisionWrapper.Decision.DecisionTarget.ID != 0 ||
                    decisionWrapper == null)
                {
                    ModelState.AddModelError("", "Дані введені неправильно");

                    return(Json(new
                    {
                        success = false,
                        text = ModelState.Values.SelectMany(v => v.Errors),
                        model = decisionWrapper,
                        modelstate = ModelState
                    }));
                }

                if (decisionWrapper.File != null &&
                    decisionWrapper.File.Length > 10485760)
                {
                    ModelState.AddModelError("", "файл за великий (більше 10 Мб)");

                    return(Json(new { success = false, text = "file length > 10485760" }));
                }

                decisionWrapper.Decision.HaveFile = decisionWrapper.File != null;
                decisionWrapper.Decision.ID       = await _decisionService.SaveDecisionAsync(
                    _mapper.Map <DecisionWrapperDTO>(decisionWrapper));

                return(Json(new
                {
                    success = true,
                    Text = "Рішення додано!",
                    decision = decisionWrapper.Decision,
                    decisionOrganization = (await _decisionService
                                            .GetDecisionOrganizationAsync(_mapper.Map <OrganizationDTO>(decisionWrapper.Decision.Organization)))
                                           .OrganizationName
                }));
            }
            catch (Exception e)
            {
                _loggerService.LogError($"{e.Message}");

                return(Json(new
                {
                    success = false,
                    text = e.Message
                }));
            }
        }