Пример #1
0
        private ActionResult DoCreate(ModifyMessageModel model)
        {
            ModelState.Remove(model.UrlOnly ? "Text" : "Url");
            ProcessRecipientsCsvUpload csvData = new ProcessRecipientsCsvUpload
            {
                PostedFile = model.UploadedFile,
            };

            if (!csvData.CheckCsvOk()) // check csv upload before modelstate so can process irrespectively
            {
                ModelState.AddModelError("UploadedFile", csvData.Error);
                model.RecipientList = MessageLayer.FieldToRecipientList(model.RecipientsField);
                return(View("Create", model));
            }
            if (csvData.Empty && !ModelState.IsValid)
            {
                model.RecipientList = MessageLayer.FieldToRecipientList(model.RecipientsField);
                return(View("Create", model));
            }
            var store = MessageLayer.ConvertModifyMessageModelToStoreMessage(model);

            store.UserId = User.Identity.GetUserId();
            if (!csvData.Empty)
            {
                store.Recipients = csvData.Recipients;
            }
            //model.Recipients;
            if (!MessageLayer.AddMessage(Db, store))
            {
                model.RecipientList = MessageLayer.FieldToRecipientList(model.RecipientsField);
                return(View("Create", model));
            }
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", new { id = store.NewId }));
            }
            return(RedirectToAction("Index"));
        }