public PersonnelEducation Update(int personnelId, PersonnelEducation education) { var request = _client.NewRequest("personnel/{personnelId}/education/{DegreeId}", Method.PUT); request.AddUrlSegment("personnelId", personnelId.ToString()); request.AddUrlSegment("DegreeId", education.DegreeId.ToString()); request.AddBody(education); var results = _client.Execute <PersonnelEducation>(request); return(results.Data); }
public void CreateEducationRecord() { //Any valid Personnel ID to which the education would be associated var _personnelId = 1079654; var education = new PersonnelEducation { DegreeId = 0, Major = "Information Systems", School = "University of Boston", Year = "2017", SF330_DegreeInd = 0 }; var result = _context.AddEducationToPersonnel(_personnelId, education); Assert.IsNotNull(result); }
public PersonnelEducation AddEducationToPersonnel(int personnelId, PersonnelEducation education) { return(Create(personnelId, new PersonnelEducation[] { education }).FirstOrDefault()); }
public ActionResult Edit(Person person) { person.BirthDay = MyConvertToDateTime(person.BirthDayString); using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { if (person.Id.IsNullOrWhiteSpace() || person.Id.Equals(Guid.Empty)) { person.Id = Guid.NewGuid().ToString(); person.CreatedOn = DateTime.Now; db.Person.Add(person); } else { var existingPersonnel = db.Person.First(x => x.CompanyId == person.CompanyId && x.Id == person.Id); person.CreatedOn = existingPersonnel.CreatedOn; db.Entry(existingPersonnel).State = EntityState.Detached; existingPersonnel = null; db.Entry(person).State = EntityState.Modified; } db.SaveChanges(); //********************************************************************// var telephoneList = FillTelefonListPersonnel(person.Id, person.CompanyId); db.PersonnelTelephone.RemoveRange(db.PersonnelTelephone.Where(x => x.CompanyId == person.CompanyId && x.PersonnelId == person.Id)); if (telephoneList.Any()) { db.PersonnelTelephone.AddRange(telephoneList); db.SaveChanges(); } //*****************************************************************// var addressList = FillAddressListPersonnel(person.CompanyId, person.Id); db.PersonnelAddress.RemoveRange(db.PersonnelAddress .Where(x => x.CompanyId == person.CompanyId && x.PersonnelId == person.Id)); if (addressList.IsEmpty().Not()) { db.PersonnelAddress.AddRange(addressList); db.SaveChanges(); } //******************************************************************// var bankList = FillPersonnelBankList(person.CompanyId, person.Id); db.PersonnelBank.RemoveRange(db.PersonnelBank.Where(x => x.CompanyId == person.CompanyId && x.PersonnelId == person.Id)); if (bankList.Any()) { db.PersonnelBank.AddRange(bankList); db.SaveChanges(); } //******************************************************************// //group-education[0][EducationLevelId] var educationList = new List <PersonnelEducation>(); var i = 0; while (true) { var educationLevelId = Request["group-education[" + i + "][EducationLevelId]"]; var studiedSchoolName = Request["group-education[" + i + "][StudiedSchoolName]"]; var educationArea = Request["group-education[" + i + "][EducationArea]"]; var id = Request["group-education[" + i + "][EducationId]"]; if (string.IsNullOrWhiteSpace(studiedSchoolName)) { break; } var education = new PersonnelEducation(); education.EducationLevelId = educationLevelId.AsInt(); education.StudiedSchoolName = studiedSchoolName; education.EducationArea = educationArea; education.Id = id.AsInt(); educationList.Add(education); i++; } var existingEducations = db.PersonnelEducation.Where(x => x.PersonnelId == person.Id && !x.IsPassive).ToList(); foreach (var item in existingEducations) { item.IsPassive = true; item.MakedPassiveBy = User.Identity.GetUserId(); item.MakedPassiveOn = DateTime.UtcNow; db.Entry(item).State = EntityState.Modified; } if (educationList.Any()) { var dicExistingEducations = existingEducations.ToDictionary(x => x.Id); foreach (var item in educationList) { if (dicExistingEducations.ContainsKey(item.Id)) { dicExistingEducations[item.Id].IsPassive = false; dicExistingEducations[item.Id].MakedPassiveBy = null; dicExistingEducations[item.Id].MakedPassiveOn = null; dicExistingEducations[item.Id].ChangedBy = User.Identity.GetUserId(); dicExistingEducations[item.Id].ChangedOn = DateTime.UtcNow; dicExistingEducations[item.Id].EducationLevelId = item.EducationLevelId; dicExistingEducations[item.Id].StudiedSchoolName = item.StudiedSchoolName; dicExistingEducations[item.Id].EducationArea = item.EducationArea; } else { item.CreatedOn = DateTime.UtcNow; item.CreatedBy = User.Identity.GetUserId(); item.PersonnelId = person.Id; db.PersonnelEducation.Add(item); } } db.SaveChanges(); } //******************************************************************// SaveEntityTerms(GetListNewTerms(TaxonomyTypeForPersonnel, person.CompanyId), person.Id, person.CompanyId); db.SaveChanges(); transaction.Commit(); return(RedirectToAction(actionName: "Index", controllerName: "GuideBook")); //foreach (ModelState modelState in ViewData.ModelState.Values) //{ // foreach (ModelError error in modelState.Errors) // { // var te = error.ErrorMessage; // } //} } catch (Exception ex) { ViewBag.PositionId = new SelectList(db.Term.Where(x => x.TaxonomyId == (int)TaxonomyType.Position), "Id", "Name", person.PositionId); ViewBag.CompanyId = new SelectList(db.Company, "Id", "Name", person.CompanyId); ViewBag.RelationshipStatusId = new SelectList( db.Term.Where(x => x.TaxonomyId == (int)TaxonomyType.RelationshipStatus).ToList() , "Id", "Name", person.RelationshipStatusId); ViewBag.ReligionId = new SelectList( db.Term.Where(x => x.TaxonomyId == (int)TaxonomyType.Religion).ToList() , "Id", "Name", person.ReligionId); ViewBag.BloodGroupId = new SelectList( db.Term.Where(x => x.TaxonomyId == (int)TaxonomyType.BloodGroup).ToList() , "Id", "Name", person.BloodGroupId); ViewBag.ReasonWhyPassiveId = new SelectList( db.Term.Where(x => x.TaxonomyId == (int)TaxonomyType.ReasonWhyPassiveForPersonnel).ToList() , "Id", "Name", person.ReasonWhyPassiveId); transaction.Rollback(); ViewBag.ErrorMessage = "<p>" + ex.ToString() + "</p>"; return(View(person)); } } }