Пример #1
0
        public async Task <JsonResult> AddReceivedEdit(DeliveryItem model, string guidForSave)
        {
            SetViewbag(userContext.CourtId);
            SetViewbagArea(userContext.CourtId);

            string viewAdd               = "";
            string viewSaved             = "";
            string saveOk                = "";
            string saveFailed            = "";
            bool   isOk                  = false;
            string messageErr            = IsExists(model);
            List <SelectListItem> errors = null;

            ViewBag.conteinerId = guidForSave;
            string conteinerIdAdd = ViewBag.conteinerId;

            ValidateModel(model);
            if (!ModelState.IsValid)
            {
                viewAdd = await RenderPartialViewToString("_AddReceived", model);

                errors = ModelState.Where(x => x.Value.ValidationState == ModelValidationState.Invalid)
                         .Select(x => new SelectListItem()
                {
                    Value = x.Key, Text = x.Value.Errors.First().ErrorMessage
                })
                         .ToList();
                //errors = modelErrors.Select(x => new SelectListItem() {Value = x.Key, Text = x. })
            }
            else
            {
                model.CaseNotificationId  = null;
                model.NotificationStateId = NomenclatureConstants.NotificationState.Received;
                if (service.DeliveryItemSaveDataAddReceived(model))
                {
                    isOk = true;

                    saveOk = MessageConstant.Values.SaveOK;
                    DeliveryItem newModel = new DeliveryItem();
                    newModel.FromCourtId = model.FromCourtId;
                    var guid = Guid.NewGuid();
                    ViewBag.conteinerId = guid;
                    conteinerIdAdd      = guid.ToString();
                    viewAdd             = await RenderPartialViewToString("_AddReceived", newModel);

                    ViewBag.showButtons = false;
                    ViewBag.conteinerId = Guid.NewGuid();
                    viewSaved           = await RenderPartialViewToString("_AddReceived", model);
                }
                else
                {
                    saveFailed = MessageConstant.Values.SaveFailed;
                    viewAdd    = await RenderPartialViewToString("_AddReceived", model);
                }
            }
            return(Json(new {
                isOk,
                messageErr,
                viewAdd,
                viewSaved,
                saveOk,
                saveFailed,
                conteinerIdAdd,
                errors
            }));
        }