예제 #1
0
        public async Task <IActionResult> EditData(string identifier, ImapExternalServiceData data)
        {
            var result = await GetExternalServiceData(identifier);

            if (result.Error != null)
            {
                return(result.Error);
            }

            var externalServiceData = result.Data;

            if (!ModelState.IsValid)
            {
                return(View(data));
            }
            data.PairedDate = DateTime.Now;
            externalServiceData.Set(data);

            var imapService    = new ImapService(externalServiceData);
            var testConnection = await imapService.CreateClientAndConnect();

            if (testConnection == null)
            {
                ModelState.AddModelError(string.Empty, "Could not connect successfully");

                return(View(data));
            }

            testConnection.Dispose();


            await _externalServiceManager.AddOrUpdateExternalServiceData(externalServiceData);

            return(RedirectToAction("EditExternalService", "ExternalServices", new
            {
                id = externalServiceData.Id,
                statusMessage = "Imap Data updated"
            }));
        }
예제 #2
0
        protected override async Task <(ExternalServiceData ToSave, ImapExternalServiceData showViewModel)> BuildModel(ImapExternalServiceData viewModel, ExternalServiceData mainModel)
        {
            if (!ModelState.IsValid)
            {
                return(null, viewModel);
            }
            viewModel.PairedDate = DateTime.Now;
            mainModel.Set(viewModel);

            var imapService    = new ImapService(mainModel);
            var testConnection = await imapService.CreateClientAndConnect();

            if (testConnection == null)
            {
                ModelState.AddModelError(string.Empty, "Could not connect successfully");

                return(null, viewModel);
            }

            testConnection.Dispose();
            return(mainModel, null);
        }