Esempio n. 1
0
        public async Task <IActionResult> Index(EditApprenticeshipViewModel model)
        {
            if (model.ApprenticeshipId.HasValue)
            {
                string apprenticeshipGuidId = model.ApprenticeshipId.ToString();

                var apprenticeshipForEdit = await _apprenticeshipService.GetApprenticeshipByIdAsync(apprenticeshipGuidId);

                if (apprenticeshipForEdit.IsSuccess)
                {
                    apprenticeshipForEdit.Value.MarketingInformation = model?.Information;
                    apprenticeshipForEdit.Value.ContactEmail         = model?.Email;
                    apprenticeshipForEdit.Value.ContactWebsite       = model?.WebSite;
                    apprenticeshipForEdit.Value.ContactTelephone     = model?.Telephone;
                    apprenticeshipForEdit.Value.Url              = model?.ContactUsURL;
                    apprenticeshipForEdit.Value.UpdatedBy        = User.Claims.Where(c => c.Type == "email").Select(c => c.Value).SingleOrDefault(); // User.Identity.Name;
                    apprenticeshipForEdit.Value.UpdatedDate      = DateTime.Now;
                    apprenticeshipForEdit.Value.BulkUploadErrors = new List <BulkUploadError> {
                    };
                    if (apprenticeshipForEdit.Value.BulkUploadErrors.Count() == 0)
                    {
                        apprenticeshipForEdit.Value.RecordStatus = Services.Models.RecordStatus.BulkUploadReadyToGoLive;
                    }
                    var updatedApprenticeship = await _apprenticeshipService.UpdateApprenticeshipAsync(apprenticeshipForEdit.Value);
                }

                return(RedirectToAction("Index", "PublishApprenticeships"));
            }

            return(View("Error", new ErrorViewModel {
                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
            }));
        }
        public async Task <IActionResult> Summary(SummaryViewModel theModel)
        {
            int UKPRN;

            if (_session.GetInt32("UKPRN") != null)
            {
                UKPRN = _session.GetInt32("UKPRN").Value;
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." }));
            }

            var Apprenticeship = _session.GetObject <Apprenticeship>("selectedApprenticeship");

            var mode = _session.GetObject <ApprenticeshipMode>("ApprenticeshipMode");

            if (mode == ApprenticeshipMode.EditYourApprenticeships)
            {
                var result = await _apprenticeshipService.UpdateApprenticeshipAsync(Apprenticeship);

                if (result.IsSuccess)
                {
                    return(RedirectToAction("Index", "ProviderApprenticeships", new { apprenticeshipId = result.Value.id, message = "You edited " + result.Value.ApprenticeshipTitle }));
                }
                else
                {
                    //Action needs to be decided if failure
                    return(RedirectToAction("Summary", "Apprenticeships"));
                }
            }
            else
            {
                Apprenticeship.id = Guid.NewGuid();
                var result = await _apprenticeshipService.AddApprenticeship(Apprenticeship);

                if (result.IsSuccess)
                {
                    return(RedirectToAction("Complete", "Apprenticeships"));
                }
                else
                {
                    //Action needs to be decided if failure
                    return(RedirectToAction("Summary", "Apprenticeships"));
                }
            }
        }
        internal IEnumerable <Apprenticeship> GetErrorMessages(IEnumerable <Apprenticeship> apprenticeships)
        {
            foreach (var apprentice in apprenticeships)
            {
                apprentice.ValidationErrors = ValidateApprenticeships(apprentice).Select(x => x.Value);

                apprentice.LocationValidationErrors = ValidateApprenticeshipLocations(apprentice).Select(x => x.Value);

                if (apprentice.BulkUploadErrors.Any() && !apprentice.ValidationErrors.Any())
                {
                    apprentice.BulkUploadErrors = new List <BulkUploadError> {
                    };
                }

                _apprenticeshipService.UpdateApprenticeshipAsync(apprentice);
            }

            return(apprenticeships);
        }