public async Task <IActionResult> EditData(string identifier)
        {
            var result = await GetExternalServiceData(identifier);

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

            var pop3Service = new Pop3Service(result.Data);

            return(View(pop3Service.GetData()));
        }
Ejemplo n.º 2
0
        protected override async Task <(ExternalServiceData ToSave, Pop3ExternalServiceData showViewModel)> BuildModel(Pop3ExternalServiceData viewModel, ExternalServiceData mainModel)
        {
            if (!ModelState.IsValid)
            {
                return(null, viewModel);
            }
            mainModel.Set(viewModel);

            var imapService    = new Pop3Service(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);
        }
        public async Task <IActionResult> EditData(string identifier, Pop3ExternalServiceData data)
        {
            var result = await GetExternalServiceData(identifier);

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

            var externalServiceData = result.Data;

            if (!ModelState.IsValid)
            {
                return(View(data));
            }

            externalServiceData.Set(data);

            var pop3Service    = new Pop3Service(externalServiceData);
            var testConnection = await pop3Service.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 = "Pop3 Data updated"
            }));
        }