Inheritance: ExtensibleDataObject
        public async Task <IActionResult> CreateAsync([FromBody] JobCategory model)
        {
            try
            {
                if (model.ValidationErrors().Any())
                {
                    return(StatusCode((int)HttpStatusCode.PreconditionFailed, string.Join(" | ", model.ValidationErrors())));
                }

                var newJobCategory = new JobCategory
                {
                    Id          = model.Id,
                    Name        = model.Name,
                    Description = model.Description,
                    CreatedOn   = DateTime.Now,
                    UpdatedOn   = DateTime.Now,
                    IsDisplayed = true,
                    IsDeleted   = false
                };

                var result = await _service.AddJobCategoryAsync(newJobCategory);

                if (result)
                {
                    return(StatusCode((int)HttpStatusCode.OK, "Job Category created successfully !!!"));
                }
                return(StatusCode((int)HttpStatusCode.OK, "Job Category not created !!!"));
            }
            catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); }
        }
        public ActionResult Edit(JobCategory model)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new JobCategoriesViewModel(model);

                return(View());
            }


            var categoryInDb = _context.JobCategories.SingleOrDefault(m => m.Id == model.Id);

            if (categoryInDb == null)
            {
                return(HttpNotFound());
            }

            categoryInDb.Name        = model.Name;
            categoryInDb.Description = model.Description;


            _context.SaveChanges();

            return(RedirectToAction("ViewAll"));
        }
Ejemplo n.º 3
0
        private void copyCategories(Server destserver)
        {
            foreach (JobCategory cat in sourceserver.JobServer.JobCategories)
            {
                string     categoryname = cat.Name;
                ItemToCopy item         = itemsToCopy.Find(x => x.Name == categoryname);
                if (item.IsChecked)
                {
                    if (DBChecks.CategoryExists(destserver, categoryname))
                    {
                        showOutput.displayOutput(string.Format("Category {0} already exists in destination. Skipping.", categoryname));
                        continue;
                    }

                    try
                    {
                        JobCategory destcat = new JobCategory();
                        destcat.Name         = categoryname;
                        destcat.Parent       = destserver.JobServer;
                        destcat.CategoryType = cat.CategoryType;
                        destcat.Create();
                    }
                    catch (Exception ex)
                    {
                        showOutput.displayOutput(ex.Message);
                        continue;
                    }

                    showOutput.displayOutput(string.Format("Copied category {0} to destination", categoryname));
                }
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Desscription")] JobCategory jobCategory)
        {
            if (id != jobCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _jobCategoryService.UpdateAsync(jobCategory);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (await JobCategoryExists(id) == false)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(jobCategory));
        }
Ejemplo n.º 5
0
        public async Task UpdateJobCategory(JobCategory jobCategory)
        {
            var jobCategoryJson =
                new StringContent(JsonSerializer.Serialize(jobCategory), Encoding.UTF8, "application/json");

            await _httpClient.PutAsync("api/jobcategory", jobCategoryJson);
        }
Ejemplo n.º 6
0
        public ActionResult Create(JobCategoryModel model)
        {
            if (ModelState.IsValid)
            {
                var jobCategory = new JobCategory
                {
                    Name     = model.Name,
                    IsActive = model.IsActive
                };

                var result = jobCategoryService.Insert(jobCategory);
                if (result)
                {
                    this.NotifySuccess("Successfully saved.");
                }
                else
                {
                    this.NotifyError("Item can not saved!");
                }

                var urlRecord = new UrlRecord
                {
                    EntityId   = jobCategory.Id,
                    EntityName = nameof(JobCategory),
                    Slug       = model.Name.ToUrlSlug()
                };
                urlService.Save(urlRecord);

                return(RedirectToAction("Edit", new { Id = jobCategory.Id }));
            }

            return(View(model));
        }
        public async Task Details_Given_ExistingItemId_Should_ReturnCorrectViewModel()
        {
            // Arrange
            var item1 = new JobCategory {
                Name = "Item1"
            };
            var item2 = new JobCategory {
                Name = "Item2"
            };
            var item3 = new JobCategory {
                Name = "Item3"
            };
            var expectedName = item2.Name;

            var serviceMock = new Mock <IJobCategoryService>();

            serviceMock.Setup(x => x.GetCategoryById("1")).ReturnsAsync(item1);
            serviceMock.Setup(x => x.GetCategoryById("2")).ReturnsAsync(item2);
            serviceMock.Setup(x => x.GetCategoryById("3")).ReturnsAsync(item3);

            var controller = new JobCategoryController(serviceMock.Object, _mapper);

            // Act
            var result = await controller.Details("2");

            // Assert
            var viewResult = (ViewResult)result;
            var model      = (DetailsJobCategoryViewModel)viewResult.Model;

            Assert.Equal(expectedName, model.Name);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, JobCategory category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(category));
        }
Ejemplo n.º 9
0
        public ApiResponse InsertJobCategory(JobCategory newJobCategory)
        {
            using (var context = new AgmDataContext())
            {
                var email = (Thread.CurrentPrincipal as CustomPrincipal).User.Split('$').GetValue(0) as string;
                var user  = context.Users.Single(u => u.Email == email);

                if (!user.SectionUsersVisible)
                {
                    return(new ApiResponse(false));
                }

                if (context.JobCategories.Any(r => r.Name == newJobCategory.Name && r.IsDeleted == false))
                {
                    return new ApiResponse(false)
                           {
                               Errors = new ApiResponseError[] { new ApiResponseError()
                                                                 {
                                                                     Message = "Categoria già esistente!"
                                                                 } }
                           }
                }
                ;

                context.JobCategories.Add(newJobCategory);
                context.SaveChanges();

                return(new ApiResponse(true));
            }
        }
        public void CreateJobPostDBTest()
        {
            //Arrange
            DbCompany dbCompany = new DbCompany();
            Company   company   = new Company("*****@*****.**", "hellopassword");

            company.Id = 1;
            WorkHours workHours = new WorkHours();

            workHours.Id = 1;
            JobCategory jobCategory = new JobCategory();

            jobCategory.Id = 1;


            string   iDate   = "05/05/2018";
            DateTime oDate   = Convert.ToDateTime(iDate);
            JobPost  jobPost = new JobPost(1, "Test job1", "Et job for dig", DateTime.Now, oDate, "Wc Vasker", workHours, "Her", company, jobCategory);



            //Act
            //bool inserted = dbCompany.createJobPost(jobPost);

            //Assert
            // Assert.IsTrue(inserted);
        }
Ejemplo n.º 11
0
        public IActionResult UpdateJobCategory([FromBody] JobCategory jobCategory)
        {
            if (jobCategory == null)
            {
                return(BadRequest());
            }

            if (jobCategory.JobCategoryName == string.Empty)
            {
                ModelState.AddModelError("JobCategoryName", "The Job Category Name Is Required!");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var jobCategoryToUpdate = _jobCategoryRepository.GetJobCategoryById(jobCategory.JobCategoryId);

            if (jobCategoryToUpdate == null)
            {
                return(NotFound());
            }

            _jobCategoryRepository.UpdateJobCategory(jobCategory);

            return(NoContent()); //success
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("CategoryName,ID")] JobCategory jobCategory)
        {
            if (id != jobCategory.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(jobCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!JobCategoryExists(jobCategory.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(jobCategory));
        }
Ejemplo n.º 13
0
        public async Task <bool> Delete(JobCategory item)
        {
            _repo.Delete(item);
            await _unitOfWork.Save();

            return(true);
        }
        public async Task <bool> UpdateJobCategoryAsync(JobCategory jobCategory)
        {
            _repo.Update(jobCategory);
            var result = Task.Run(() => _repo.SaveAll());

            return(await result);
        }
Ejemplo n.º 15
0
        public JobCategory AddJobCategory(JobCategory jobCategory)
        {
            var addedEntity = _appDbContext.JobCategories.Add(jobCategory);

            _appDbContext.SaveChanges();
            return(addedEntity.Entity);
        }
        public async Task PagesControllerBodyReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            const string article        = "an-article-name";
            var          expectedResult = new JobCategory()
            {
                Title = "Care Worker"
            };
            var controller = BuildPagesController(mediaTypeName);

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string?> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <JobCategory> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>());

            // Act
            var result = await controller.Body(article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var statusResult = Assert.IsType <StatusCodeResult>(result);

            A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

            controller.Dispose();
        }
 public ActionResult SaveOrUpdateJobCategory(JobCategory model)
 {
     try
     {
         if (model.Id > 0)
         {
             var current = JobCategoryProvider.GetKey(model.Id);
             model.Modified   = DateTime.Now;
             model.ModifiedBy = User.Identity.GetUserName();
             model.Created    = current.Created;
             model.CreatedBy  = current.CreatedBy;
         }
         else
         {
             model.Created   = DateTime.Now;
             model.Modified  = DateTime.Now;
             model.CreatedBy = User.Identity.GetUserName();
         }
         var result = JobCategoryProvider.SaveOrUpdate(model);
         JobCategoryProvider.SaveOrUpdate(model);
         return(Json(SuccessApiResponse));
     }
     catch (Exception)
     {
         return(Json(new ApiResponse <object>
         {
             BRuleCode = 1,
             Message = RuleExceptionCodeCommon.OtherError.GetEnumDescription()
         }));
     }
 }
        public async Task Details_Given_IdThatDoesNotExist_Should_ReturnNotFoundView()
        {
            // Arrange
            var item1 = new JobCategory {
                Name = "Item1"
            };
            var item2 = new JobCategory {
                Name = "Item2"
            };
            var item3 = new JobCategory {
                Name = "Item3"
            };

            var serviceMock = new Mock <IJobCategoryService>();

            serviceMock.Setup(x => x.GetCategoryById("1")).ReturnsAsync(item1);
            serviceMock.Setup(x => x.GetCategoryById("2")).ReturnsAsync(item2);
            serviceMock.Setup(x => x.GetCategoryById("3")).ReturnsAsync(item3);

            var controller = new JobCategoryController(serviceMock.Object, _mapper);

            // Act
            var result = await controller.Details("9");

            // Assert
            var viewResult = (ViewResult)result;

            Assert.Equal("NotFound", viewResult.ViewName);
        }
Ejemplo n.º 19
0
        protected virtual JobCategory GetJobCategoryFromReader(IDataReader reader)
        {
            EntityConverter <JobCategory> jobCategoryEntity = new EntityConverter <JobCategory>();
            JobCategory jobCategory = jobCategoryEntity.Convert(reader);

            return(jobCategory);
        }
        public async Task <IActionResult> Patch(int id, [FromBody] JobCategory model)
        {
            try
            {
                var entity = _service.GetJobCategoryById(id);
                if (entity == null)
                {
                    return(NotFound());
                }

                if (model.ValidationErrors().Any())
                {
                    return(StatusCode((int)HttpStatusCode.PreconditionFailed, string.Join(" | ", model.ValidationErrors())));
                }

                //Update Job category
                entity.Name        = model.Name;
                entity.Description = model.Description;
                entity.UpdatedOn   = DateTime.Now;

                if (await _service.UpdateJobCategoryAsync(entity))
                {
                    return(StatusCode((int)HttpStatusCode.OK, "Job category updated successfully !!!"));
                }
                return(StatusCode((int)HttpStatusCode.OK, "Job category not updated !!!"));
            }
            catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); }
        }
        public async Task PagesControllerBodyWithNullArticleHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            const string?article        = null;
            var          expectedResult = new JobCategory()
            {
                Title = "Care Worker"
            };
            var controller = BuildPagesController(mediaTypeName);

            expectedResult.CanonicalName = article;

            A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <JobCategory> .Ignored, A <BodyViewModel> .Ignored)).Returns(A.Fake <BodyViewModel>());

            // Act
            var result = await controller.Body(article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeJobCategoryContentPageService.GetByCanonicalNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var viewResult = Assert.IsType <ViewResult>(result);

            _ = Assert.IsAssignableFrom <BodyViewModel>(viewResult.ViewData.Model);

            controller.Dispose();
        }
 public ActionResult <ResponseContext> GetLoaiCV(string JobCategoryId)
 {
     try
     {
         if ((bool)HttpContext.Items["isLoggedInOtherDevice"])
         {
             return(Ok(new ResponseContext
             {
                 code = (int)Common.ResponseCode.IS_LOGGED_IN_ORTHER_DEVICE,
                 message = Common.Message.IS_LOGGED_IN_ORTHER_DEVICE,
                 data = null
             }));
         }
         var objLoaiCV = new JobCategory();
         objLoaiCV = _loaiCVServices.GetJobCategoryByCategoryId(JobCategoryId);
         return(Ok(new ResponseContext
         {
             code = (int)Common.ResponseCode.SUCCESS,
             message = Common.Message.SUCCESS,
             data = objLoaiCV
         }));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         return(StatusCode(StatusCodes.Status500InternalServerError, new ResponseMessage
         {
             status = "ERROR",
             message = ex.Message
         }));
     }
 }
Ejemplo n.º 23
0
        protected override void ProcessRecord()
        {
            JobCategory jobCat = this.GetJobCategory(this.Identity);

            if (base.Force || base.ShouldProcess(jobCat.Name, "Modifying properties"))
            {
                if (this.MyInvocation.BoundParameters.ContainsKey("NewType") && jobCat.CategoryType != this.NewType)
                {
                    jobCat.CategoryType = this.NewType;
                }

                else if (this.MyInvocation.BoundParameters.ContainsKey("NewType"))
                {
                    base.WriteWarning(jobCat.Name + " is already of type " + this.NewType.ToString() + ".");
                }

                if (this.MyInvocation.BoundParameters.ContainsKey("NewName") && !jobCat.Name.Equals(this.NewName, StringComparison.CurrentCulture))
                {
                    jobCat.Rename(this.NewName);
                }

                else if (this.MyInvocation.BoundParameters.ContainsKey("NewName"))
                {
                    base.WriteWarning("The new name specified is the same as the existing name (" + jobCat.Name + ").");
                }

                _js.Refresh();
            }
        }
Ejemplo n.º 24
0
 public ActionResult Create(JobCategory jobCategory)
 {
     jobCategory.AddedBy   = User.Identity.GetUserName();
     jobCategory.DateAdded = DateTime.Now;
     _context.JobCategories.Add(jobCategory);
     _context.SaveChanges();
     return(RedirectToAction("Index", "JobCategories"));
 }
Ejemplo n.º 25
0
 public List <JobSubcategory> GetCategorySubcategories(JobCategory jobCategory)
 {
     if (jobCategory == null)
     {
         return(new List <JobSubcategory>());
     }
     return(GetListFromIds(GetCategorySubcategoryIds(jobCategory.Id)));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            JobCategory jobCategory = db.JobCategories.Find(id);

            db.JobCategories.Remove(jobCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <bool> AddJobCategoryAsync(JobCategory jobCategory)
        {
            await _repo.AddAsync(jobCategory);

            var result = Task.Run(() => _repo.SaveAll());

            return(await result);
        }
Ejemplo n.º 28
0
        public void AddCategory()
        {
            JobCategory item = new JobCategory();

            JobCategoryRepository.Instance.SetItem(item);

            Categories.Add(item);
            SelectedCategory = item;
        }
        public async Task <ActionResult> DeleteConfirmed(long id)
        {
            JobCategory jobCategory = await db.JobCategories.FindAsync(id);

            db.JobCategories.Remove(jobCategory);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 30
0
        public LocalizableCategory(JobCategory category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            this.category = category;
            categoryName  = LookupLocalizableName(category);
        }
Ejemplo n.º 31
0
        public static string AddJobCategory(Guid job_id, Guid cat_id)
        {
            JobBoardDataContext db = new JobBoardDataContext();

            // Lets make sure we don't already have an association for this category
            int exists = db.JobCategories.Where(x => x.cat == cat_id && x.job == job_id).Count();
            if (exists > 0) { return "You may not add this category more than once."; }

            JobCategory jc = new JobCategory {
                job = job_id,
                cat = cat_id
            };
            db.JobCategories.InsertOnSubmit(jc);
            db.SubmitChanges();

            JobCategory json = new JobCategory {
                id = jc.id,
                job = jc.job,
                cat = jc.cat
            };
            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(json);
        }
Ejemplo n.º 32
0
        //Create new job
        public bool CreateJob(JobCreateModel model, string JobPackageName, string skill1, string skill2, string skill3, string recruiterID)
        {
            //try
            //{
            JobPackage jobPackage = this.JobPackageRepository.Get(s => s.Name == JobPackageName).FirstOrDefault();
            if (jobPackage == null)
            {
                return false;
            }
            PurchaseJobPackage purchaseJobPackage = (from p in this.PurchaseJobPackageRepository.Get()
                                                     join j in this.JobPackageRepository.Get() on p.JobPackageID equals j.JobPackageID
                                                     where p.RecruiterID == recruiterID && p.IsApproved == true && p.IsDeleted == false
                                                        && p.JobPackageID == jobPackage.JobPackageID
                                                        && (from jo in this.JobRepository.Get()
                                                            where jo.PurchaseJobPackageId == p.PurchaseJobPackageID
                                                            select jo).Count() < j.JobNumber
                                                     select p)
                                                     .AsEnumerable().FirstOrDefault();
            if (purchaseJobPackage == null)
            {
                return false;
            }

            this.JobRepository.Insert(Model_Job(model, purchaseJobPackage.PurchaseJobPackageID));
            this.Save();

            Job temp = this.JobRepository.Get(job => job.RecruiterID == model.JobInfo.RecruiterID && job.JobTitle == model.JobInfo.JobTitle).Last();

            //Add city
            foreach (int index in model.CitySelectList)
            {
                JobCity item = new JobCity();
                item.JobID = temp.JobID;
                item.CityID = index;
                this.JobCityRepository.Insert(item);
                this.Save();
            }

            //Add category
            foreach (int index in model.CategorySelectList)
            {
                JobCategory item = new JobCategory();
                item.JobID = temp.JobID;
                item.CategoryID = index;
                this.JobCategoryRepository.Insert(item);
                this.Save();
            }

            //Skill part
            if (!String.IsNullOrEmpty(skill1))
            {
                Skill s1 = this.SkillRepository.Get(skill => skill.SkillTag == skill1).SingleOrDefault();
                if (s1 != null)
                {
                    JobSkill tempjs1 = new JobSkill();
                    tempjs1.JobID = temp.JobID;
                    tempjs1.Skill_ID = s1.Skill_ID;
                    tempjs1.IsDeleted = false;
                    this.JobSkillRepository.Insert(tempjs1);
                    this.Save();
                }
                else
                {
                    Skill temps1 = new Skill();
                    temps1.SkillTag = skill1;
                    temps1.IsDeleted = false;
                    this.SkillRepository.Insert(temps1);
                    this.Save();
                    JobSkill tempjs1 = new JobSkill();
                    tempjs1.JobID = temp.JobID;
                    tempjs1.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps1.SkillTag).LastOrDefault().Skill_ID;
                    tempjs1.IsDeleted = false;
                    this.JobSkillRepository.Insert(tempjs1);
                    this.Save();
                }
            }

            if (!String.IsNullOrEmpty(skill2))
            {
                Skill s2 = this.SkillRepository.Get(skill => skill.SkillTag == skill2).SingleOrDefault();
                if (s2 != null)
                {
                    JobSkill tempjs2 = new JobSkill();
                    tempjs2.JobID = temp.JobID;
                    tempjs2.Skill_ID = s2.Skill_ID;
                    tempjs2.IsDeleted = false;
                    this.JobSkillRepository.Insert(tempjs2);
                    this.Save();
                }
                else
                {
                    Skill temps2 = new Skill();
                    temps2.SkillTag = skill2;
                    temps2.IsDeleted = false;
                    this.SkillRepository.Insert(temps2);
                    this.Save();
                    JobSkill tempjs2 = new JobSkill();
                    tempjs2.JobID = temp.JobID;
                    tempjs2.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps2.SkillTag).LastOrDefault().Skill_ID;
                    tempjs2.IsDeleted = false;
                    this.JobSkillRepository.Insert(tempjs2);
                    this.Save();
                }
            }
            if (!String.IsNullOrEmpty(skill3))
            {
                Skill s3 = this.SkillRepository.Get(skill => skill.SkillTag == skill3).SingleOrDefault();
                if (s3 != null)
                {
                    JobSkill tempjs3 = new JobSkill();
                    tempjs3.JobID = temp.JobID;
                    tempjs3.Skill_ID = s3.Skill_ID;
                    tempjs3.IsDeleted = false;
                    this.JobSkillRepository.Insert(tempjs3);
                    this.Save();
                }
                else
                {
                    Skill temps3 = new Skill();
                    temps3.SkillTag = skill3;
                    temps3.IsDeleted = false;
                    this.SkillRepository.Insert(temps3);
                    this.Save();
                    JobSkill tempjs3 = new JobSkill();
                    tempjs3.JobID = temp.JobID;
                    tempjs3.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps3.SkillTag).LastOrDefault().Skill_ID;
                    tempjs3.IsDeleted = false;
                    this.JobSkillRepository.Insert(tempjs3);
                    this.Save();
                }
            }
            return true;
            //}
            //catch
            //{
            //    return false;
            //}
        }
Ejemplo n.º 33
0
        public static Guid Create(string title, string short_desc, string salary_type, string status, string long_desc, Guid experience, Guid education, Guid location, Guid contact, int isDriving, List<Guid> categories, List<Guid> shifts)
        {
            JobBoardDataContext db = new JobBoardDataContext();

            // Create the new job record
            Job new_job = new Job {
                id = Guid.NewGuid(),
                title = title,
                short_desc = short_desc,
                long_desc = long_desc.Replace("\n","<br />"),
                experience = experience,
                education = education,
                location = location,
                contact = contact,
                date_added = DateTime.Now,
                isDriving = isDriving,
                salary_type = salary_type,
                status = status,
                jobState = JobState.CREATED.ToString()
            };

            // Save the job record
            db.Jobs.InsertOnSubmit(new_job);
            db.SubmitChanges();

            // Create the job categories
            foreach (Guid cat_id in categories) {
                JobCategory new_jobcat = new JobCategory {
                    job = new_job.id,
                    cat = cat_id
                };
                db.JobCategories.InsertOnSubmit(new_jobcat);
            }

            // Create the job categories
            foreach (Guid shift_id in shifts) {
                JobShift new_jobshift = new JobShift {
                    id = Guid.NewGuid(),
                    job = new_job.id,
                    shift = shift_id
                };
                db.JobShifts.InsertOnSubmit(new_jobshift);
            }

            db.SubmitChanges();
            return new_job.id;
        }
Ejemplo n.º 34
0
        //Create new job
        public bool UpdateJob(Job job, int[] citiesidlist, int[] categoriesidlist, string skill1, string skill2, string skill3, string recruiterID)
        {
            if (job != null && job.JobID > 0 && citiesidlist != null && categoriesidlist != null
                && recruiterID != null && job.RecruiterID == recruiterID)
            {
                Job oldJob = this.JobRepository.GetByID(job.JobID);

                if (oldJob != null)
                {
                    oldJob.JobTitle = job.JobTitle;
                    oldJob.MinSalary = job.MinSalary;
                    oldJob.MaxSalary = job.MaxSalary;
                    oldJob.JobDescription = job.JobDescription;
                    oldJob.JobRequirement = job.JobRequirement;
                    oldJob.JobLevel_ID = job.JobLevel_ID;
                    oldJob.MinSchoolLevel_ID = job.MinSchoolLevel_ID;

                    this.JobRepository.Update(oldJob);
                    this.Save();

                    //Add city
                    IEnumerable<JobCity> oldJobcities = this.JobCityRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable();
                    foreach (JobCity item in oldJobcities)
                    {
                        this.JobCityRepository.Delete(item);
                    }
                    this.Save();
                    foreach (int index in citiesidlist)
                    {
                        JobCity item = new JobCity();
                        item.JobID = oldJob.JobID;
                        item.CityID = index;
                        this.JobCityRepository.Insert(item);
                        this.Save();
                    }

                    //Add category
                    IEnumerable<JobCategory> oldJobcategories = this.JobCategoryRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable();
                    foreach (JobCategory item in oldJobcategories)
                    {
                        this.JobCategoryRepository.Delete(item);
                    }
                    this.Save();
                    foreach (int index in categoriesidlist)
                    {
                        JobCategory item = new JobCategory();
                        item.JobID = oldJob.JobID;
                        item.CategoryID = index;
                        this.JobCategoryRepository.Insert(item);
                        this.Save();
                    }

                    //Skill part
                    IEnumerable<JobSkill> oldJobSkill = this.JobSkillRepository.Get(s => s.JobID == oldJob.JobID).AsEnumerable();
                    foreach (JobSkill item in oldJobSkill)
                    {
                        this.JobSkillRepository.Delete(item);
                    }
                    this.Save();

                    if (!String.IsNullOrEmpty(skill1))
                    {
                        Skill s1 = this.SkillRepository.Get(skill => skill.SkillTag == skill1).SingleOrDefault();
                        if (s1 != null)
                        {
                            JobSkill tempjs1 = new JobSkill();
                            tempjs1.JobID = oldJob.JobID;
                            tempjs1.Skill_ID = s1.Skill_ID;
                            tempjs1.IsDeleted = false;
                            this.JobSkillRepository.Insert(tempjs1);
                            this.Save();
                        }
                        else
                        {
                            Skill temps1 = new Skill();
                            temps1.SkillTag = skill1;
                            temps1.IsDeleted = false;
                            this.SkillRepository.Insert(temps1);
                            this.Save();
                            JobSkill tempjs1 = new JobSkill();
                            tempjs1.JobID = oldJob.JobID;
                            tempjs1.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps1.SkillTag).LastOrDefault().Skill_ID;
                            tempjs1.IsDeleted = false;
                            this.JobSkillRepository.Insert(tempjs1);
                            this.Save();
                        }
                    }

                    if (!String.IsNullOrEmpty(skill2))
                    {
                        Skill s2 = this.SkillRepository.Get(skill => skill.SkillTag == skill2).SingleOrDefault();
                        if (s2 != null)
                        {
                            JobSkill tempjs2 = new JobSkill();
                            tempjs2.JobID = oldJob.JobID;
                            tempjs2.Skill_ID = s2.Skill_ID;
                            tempjs2.IsDeleted = false;
                            this.JobSkillRepository.Insert(tempjs2);
                            this.Save();
                        }
                        else
                        {
                            Skill temps2 = new Skill();
                            temps2.SkillTag = skill2;
                            temps2.IsDeleted = false;
                            this.SkillRepository.Insert(temps2);
                            this.Save();
                            JobSkill tempjs2 = new JobSkill();
                            tempjs2.JobID = oldJob.JobID;
                            tempjs2.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps2.SkillTag).LastOrDefault().Skill_ID;
                            tempjs2.IsDeleted = false;
                            this.JobSkillRepository.Insert(tempjs2);
                            this.Save();
                        }
                    }
                    if (!String.IsNullOrEmpty(skill3))
                    {
                        Skill s3 = this.SkillRepository.Get(skill => skill.SkillTag == skill3).SingleOrDefault();
                        if (s3 != null)
                        {
                            JobSkill tempjs3 = new JobSkill();
                            tempjs3.JobID = oldJob.JobID;
                            tempjs3.Skill_ID = s3.Skill_ID;
                            tempjs3.IsDeleted = false;
                            this.JobSkillRepository.Insert(tempjs3);
                            this.Save();
                        }
                        else
                        {
                            Skill temps3 = new Skill();
                            temps3.SkillTag = skill3;
                            temps3.IsDeleted = false;
                            this.SkillRepository.Insert(temps3);
                            this.Save();
                            JobSkill tempjs3 = new JobSkill();
                            tempjs3.JobID = oldJob.JobID;
                            tempjs3.Skill_ID = this.SkillRepository.Get(skill => skill.SkillTag == temps3.SkillTag).LastOrDefault().Skill_ID;
                            tempjs3.IsDeleted = false;
                            this.JobSkillRepository.Insert(tempjs3);
                            this.Save();
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }