Beispiel #1
0
        public ActionResult Create(PersonnelProfileViewModel personnelViewModel)
        {
            // check if user with this email already exists for the current organisation
            var userExists = UserManager.FindByEmail(personnelViewModel.Personnel.Email);

            if (userExists != null)
            {
                ModelState.AddModelError("", string.Format("An account already exists for the email address {0}", personnelViewModel.Personnel.Email));
            }

            if (ModelState.IsValid)
            {
                //Create Personnel
                personnelViewModel.Personnel = NidanBusinessService.CreatePersonnel(UserOrganisationId, personnelViewModel.Personnel);

                var result = CreateUserAndRole(personnelViewModel.Personnel);
                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }

                //delete the orphaned personnel & employment records
                NidanBusinessService.DeletePersonnel(UserOrganisationId, personnelViewModel.Personnel.PersonnelId);
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error);
                }
            }

            return(View(personnelViewModel));
        }
Beispiel #2
0
        public ActionResult Create(TrainerViewModel trainerViewModel)
        {
            var organisationId = UserOrganisationId;

            if (ModelState.IsValid)
            {
                trainerViewModel.Trainer.OrganisationId = UserOrganisationId;
                trainerViewModel.Trainer.CentreId       = UserCentreId;
                trainerViewModel.Trainer.EmailId        = trainerViewModel.Trainer.EmailId.ToLower();
                trainerViewModel.Trainer = NidanBusinessService.CreatetTrainer(UserOrganisationId, trainerViewModel.Trainer);
                var personnel = new Personnel()
                {
                    OrganisationId = organisationId,
                    DOB            = trainerViewModel.Trainer.DateOfBirth,
                    Title          = trainerViewModel.Trainer.Title,
                    Forenames      = trainerViewModel.Trainer.FirstName,
                    Surname        = trainerViewModel.Trainer.LastName,
                    Email          = trainerViewModel.Trainer.EmailId,
                    Address1       = trainerViewModel.Trainer.Address1,
                    Address2       = trainerViewModel.Trainer.Address2,
                    Address3       = trainerViewModel.Trainer.Address3,
                    Address4       = trainerViewModel.Trainer.Address4,
                    Postcode       = trainerViewModel.Trainer.PinCode.ToString(),
                    Mobile         = trainerViewModel.Trainer.Mobile.ToString(),
                    Telephone      = "12345678",
                    NINumber       = "NZ1234567",
                    CentreId       = trainerViewModel.Trainer.CentreId
                };
                NidanBusinessService.CreatePersonnel(organisationId, personnel);
                trainerViewModel.Trainer.PersonnelId = personnel.PersonnelId;
                NidanBusinessService.UpdateTrainer(organisationId, trainerViewModel.Trainer);
                CreateTrainerUserAndRole(personnel);
                return(RedirectToAction("Edit", new { id = trainerViewModel.Trainer.TrainerId }));
            }
            //trainerViewModel.Courses = new SelectList(NidanBusinessService.RetrieveCourses(organisationId, e => true).ToList());
            trainerViewModel.Sectors   = new SelectList(NidanBusinessService.RetrieveSectors(organisationId, e => true).ToList());
            trainerViewModel.Talukas   = new SelectList(NidanBusinessService.RetrieveTalukas(organisationId, e => true).ToList());
            trainerViewModel.Districts = new SelectList(NidanBusinessService.RetrieveDistricts(organisationId, e => true).ToList());
            trainerViewModel.States    = new SelectList(NidanBusinessService.RetrieveStates(organisationId, e => true).ToList());
            return(View(trainerViewModel));
        }
        public ActionResult Create(PersonnelProfileViewModel personnelViewModel)
        {
            // check if user with this email already exists for the current organisation
            var organisationId = UserOrganisationId;
            var centres        = NidanBusinessService.RetrieveCentres(organisationId, e => true);
            var userExists     = UserManager.FindByEmail(personnelViewModel.Personnel.Email);
            var roleId         = NidanBusinessService.RetrieveAspNetRoles(organisationId, e => e.Id == personnelViewModel.Role).FirstOrDefault().Name;

            personnelViewModel.Centres = new SelectList(centres, "CentreId", "Name");
            if (userExists != null)
            {
                ModelState.AddModelError("", string.Format("An account already exists for the email address {0}", personnelViewModel.Personnel.Email));
            }

            if (ModelState.IsValid)
            {
                //Create Personnel
                personnelViewModel.Personnel.CentreId = personnelViewModel.Personnel.CentreId == 0 ? UserCentreId : personnelViewModel.Personnel.CentreId;
                personnelViewModel.Personnel          = NidanBusinessService.CreatePersonnel(UserOrganisationId, personnelViewModel.Personnel);
                //var trainer =  NidanBusinessService.CreateTrainer
                //create personnel
                //var personnel = new Personnel(){set all mandatory field like forename }
                //CreateTrainerUserAndRole(personnel)
                var result = CreateUserAndRole(personnelViewModel.Personnel, roleId);
                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }

                //delete the orphaned personnel & employment records
                NidanBusinessService.DeletePersonnel(UserOrganisationId, personnelViewModel.Personnel.PersonnelId);
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error);
                }
            }

            return(View(personnelViewModel));
        }
        private Personnel Personnel(int organisationId, Enquiry enquiryData)
        {
            var personnel = new Personnel()
            {
                OrganisationId = organisationId,
                Title          = enquiryData.Title,
                Forenames      = enquiryData.FirstName,
                Surname        = enquiryData.LastName,
                DOB            = enquiryData.DateOfBirth ?? DateTime.UtcNow,
                Address1       = enquiryData.Address1,
                Address2       = enquiryData.Address2,
                Address3       = enquiryData.Address3,
                Address4       = enquiryData.Address4,
                Postcode       = enquiryData.PinCode.ToString(),
                Mobile         = enquiryData.Mobile.ToString(),
                Email          = enquiryData.EmailId,
                Telephone      = "12345678",
                NINumber       = "NZ1234567",
                CentreId       = enquiryData.CentreId
            };

            NidanBusinessService.CreatePersonnel(organisationId, personnel);
            return(personnel);
        }