public ActionResult Add(BindEmployeeExpertiseViewModel arv)
        {
            SqlLiteContext context = new SqlLiteContext();

            for (int i = 0; i < arv.Expertises.Count(); i++)
            {
                var employeeExpertise = context.EmployeeExpertises.Where(a => a.EmployeeId == arv.Expertises[i].EmployeeId && a.ExpertiseId == arv.Expertises[i].ExpertiseId).FirstOrDefault();

                if (arv.Expertises[i].Connected)
                {
                    if (employeeExpertise == null)
                    {
                        var et = new EmployeeExpertise();
                        et.EmployeeId  = arv.Expertises[i].EmployeeId;
                        et.ExpertiseId = arv.Expertises[i].ExpertiseId;
                        var entity = context.EmployeeExpertises.Add(et);
                        entity.State = EntityState.Added;
                    }
                }
                else
                {
                    if (employeeExpertise != null)
                    {
                        var entity = context.EmployeeExpertises.Remove(employeeExpertise);
                        entity.State = EntityState.Deleted;
                    }
                }
            }

            context.SaveChanges();

            return(RedirectToAction("Cv", "Home", new { id = arv.Expertises[0].EmployeeId }));
        }
Esempio n. 2
0
        private void ImportExpertise(IFileDataImporter fileImporter, IContentRepository contentRepo, EmployeeContainerLookup lookup)
        {
            string[]         allExpertise  = fileImporter.RetrieveAllData(_expertiseDataFile);
            ContentReference expertiseRoot = lookup.EmployeeSpecialityRootPage;

            foreach (string expertise in allExpertise)
            {
                EmployeeExpertise expertisePage = lookup.GetExistingPage <EmployeeExpertise>(expertiseRoot, expertise);
                if (expertisePage == null)
                {
                    expertisePage      = contentRepo.GetDefault <EmployeeExpertise>(expertiseRoot);
                    expertisePage.Name = expertise;

                    contentRepo.Save(expertisePage, EPiServer.DataAccess.SaveAction.Publish);

                    //For long running jobs periodically check if stop is signaled and if so stop execution
                    if (_stopSignaled)
                    {
                        break;
                    }
                }
            }
        }