/// <summary> /// Update a Hire Group /// </summary> public HireGroup Post(HireGroup hireGroup) { if (hireGroup == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } return(hireGroupService.UpdateHireGroup(hireGroup.CreateFrom()).CreateFrom()); }
/// <summary> /// Delete a Hire Group /// </summary> public void Delete(HireGroup hireGroup) { if (hireGroup == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } hireGroupService.DeleteHireGroup(hireGroupService.FindById(hireGroup.HireGroupId)); }
/// <summary> /// Add Hire Group /// </summary> /// <param name="hireGroup"></param> public HireGroup AddHireGroup(HireGroup hireGroup) { hireGroup.RecCreatedDt = DateTime.Now; hireGroup.RecLastUpdatedDt = DateTime.Now; hireGroup.UserDomainKey = hireGroupRepository.UserDomainKey; hireGroup.RecCreatedBy = "Cares"; hireGroup.RowVersion = 0; hireGroup.RecLastUpdatedBy = "Cares"; hireGroup.IsReadOnly = false; hireGroup.IsDeleted = false; hireGroup.IsPrivate = false; hireGroup.IsActive = false; if (hireGroup.HireGroupDetails != null) { foreach (var hireGroupDetail in hireGroup.HireGroupDetails) { hireGroupDetail.RecCreatedDt = DateTime.Now; hireGroupDetail.RecLastUpdatedDt = DateTime.Now; hireGroupDetail.UserDomainKey = hireGroupRepository.UserDomainKey; hireGroupDetail.RecCreatedBy = "Cares"; hireGroupDetail.RowVersion = 0; hireGroupDetail.RecLastUpdatedBy = "Cares"; hireGroupDetail.IsReadOnly = false; hireGroupDetail.IsDeleted = false; hireGroupDetail.IsPrivate = false; hireGroupDetail.IsActive = false; //hireGroupDetail.HireGroupId = hireGroup.HireGroupId; } } if (hireGroup.HireGroupUpGrades != null) { foreach (var hireGroupUpGrade in hireGroup.HireGroupUpGrades) { hireGroupUpGrade.RecCreatedDt = DateTime.Now; hireGroupUpGrade.RecLastUpdatedDt = DateTime.Now; hireGroupUpGrade.UserDomainKey = hireGroupRepository.UserDomainKey; hireGroupUpGrade.RecCreatedBy = "Cares"; hireGroupUpGrade.RowVersion = 0; hireGroupUpGrade.RecLastUpdatedBy = "Cares"; hireGroupUpGrade.IsReadOnly = false; hireGroupUpGrade.IsDeleted = false; hireGroupUpGrade.IsPrivate = false; hireGroupUpGrade.IsActive = false; // hireGroupUpGrade.HireGroupId = hireGroup.HireGroupId; hireGroupUpGrade.AllowedHireGroupId = hireGroupUpGrade.AllowedHireGroupId; } } hireGroupRepository.Add(hireGroup); hireGroupRepository.SaveChanges(); var hirGroup = hireGroupRepository.Find(hireGroup.HireGroupId); hireGroupRepository.LoadDependencies(hirGroup); return(hirGroup); }
/// <summary> /// Hire Group Mapper /// </summary> /// <param name="source"></param> /// <returns></returns> public static DomainModels.HireGroup CreateFromAdd(this HireGroup source) { return(new DomainModels.HireGroup { HireGroupId = source.HireGroupId, HireGroupCode = source.HireGroupCode, HireGroupName = source.HireGroupName, ParentHireGroupId = source.ParentHireGroupId, HireGroupDescription = source.Description, CompanyId = source.CompanyId, IsParent = source.IsParent, }); }
/// <summary> /// Add hire Group Request /// </summary> public static DomainModels.HireGroup CreateFrom(this HireGroup source) { return(new DomainModels.HireGroup { HireGroupDetails = source.HireGroupDetailList != null?source.HireGroupDetailList.Select(hg => hg.CreateFromForHireGroupAdd()).ToList() : null, HireGroupUpGrades = source.HireGroupUpgradeList != null?source.HireGroupUpgradeList.Select(h => h.CreateFrom()).ToList() : null, HireGroupId = source.HireGroupId, HireGroupCode = source.HireGroupCode, HireGroupName = source.HireGroupName, ParentHireGroupId = source.ParentHireGroupId, HireGroupDescription = source.Description, CompanyId = source.CompanyId, IsParent = source.IsParent, }); }
/// <summary> /// Update Hire Group /// </summary> /// <param name="hireGroup"></param> public HireGroup UpdateHireGroup(HireGroup hireGroup) { HireGroup hireGroupDbVersion = hireGroupRepository.Find(hireGroup.HireGroupId); if (hireGroupDbVersion != null) { hireGroupDbVersion.HireGroupCode = hireGroup.HireGroupCode; hireGroupDbVersion.HireGroupName = hireGroup.HireGroupName; hireGroupDbVersion.ParentHireGroupId = hireGroup.ParentHireGroupId; hireGroupDbVersion.HireGroupDescription = hireGroup.HireGroupDescription; hireGroupDbVersion.CompanyId = hireGroup.CompanyId; hireGroupDbVersion.IsParent = hireGroup.IsParent; //set child (Hire Group detail list) #region Hire Group Detial List List //add new Hire group Detail items if (hireGroup.HireGroupDetails != null) { foreach (HireGroupDetail hireGroupDetail in hireGroup.HireGroupDetails) { if ( hireGroupDbVersion.HireGroupDetails.All( x => x.HireGroupDetailId != hireGroupDetail.HireGroupDetailId) || hireGroupDetail.HireGroupDetailId == 0) { // set properties hireGroupDetail.RecCreatedDt = DateTime.Now; hireGroupDetail.RecLastUpdatedDt = DateTime.Now; hireGroupDetail.UserDomainKey = hireGroupRepository.UserDomainKey; hireGroupDetail.RecCreatedBy = "Cares"; hireGroupDetail.RowVersion = 0; hireGroupDetail.RecLastUpdatedBy = "Cares"; hireGroupDetail.IsReadOnly = false; hireGroupDetail.IsDeleted = false; hireGroupDetail.IsPrivate = false; hireGroupDetail.IsActive = false; hireGroupDetail.HireGroupId = hireGroup.HireGroupId; hireGroupDbVersion.HireGroupDetails.Add(hireGroupDetail); } } } //find missing Hire Group Detail items List <HireGroupDetail> missingHireGroupDetailItems = new List <HireGroupDetail>(); foreach (HireGroupDetail dbversionHireGroupDetailItem in hireGroupDbVersion.HireGroupDetails) { if (hireGroup.HireGroupDetails != null && hireGroup.HireGroupDetails.All(x => x.HireGroupDetailId != dbversionHireGroupDetailItem.HireGroupDetailId)) { missingHireGroupDetailItems.Add(dbversionHireGroupDetailItem); } if (hireGroup.HireGroupDetails == null) { missingHireGroupDetailItems.Add(dbversionHireGroupDetailItem); } } //remove missing Hire Group Detail items foreach (HireGroupDetail missingHireGroupDetail in missingHireGroupDetailItems) { HireGroupDetail dbVersionHireGroupDetailItem = hireGroupDbVersion.HireGroupDetails.First(x => x.HireGroupDetailId == missingHireGroupDetail.HireGroupDetailId); if (dbVersionHireGroupDetailItem.HireGroupDetailId > 0) { hireGroupDbVersion.HireGroupDetails.Remove(dbVersionHireGroupDetailItem); hireGroupDetailRepository.Delete(dbVersionHireGroupDetailItem); } } #endregion //set child (Hire Group Up Grade list) #region Hire Group Up Grade list //add new address items if (hireGroup.HireGroupUpGrades != null) { foreach (HireGroupUpGrade hireGroupUpGrade in hireGroup.HireGroupUpGrades) { if (hireGroupDbVersion.HireGroupUpGrades.All(x => x.HireGroupUpGradeId != hireGroupUpGrade.HireGroupUpGradeId) || hireGroupUpGrade.HireGroupUpGradeId == 0) { // set properties hireGroupUpGrade.RecCreatedDt = DateTime.Now; hireGroupUpGrade.RecLastUpdatedDt = DateTime.Now; hireGroupUpGrade.UserDomainKey = hireGroupRepository.UserDomainKey; hireGroupUpGrade.RecCreatedBy = "Cares"; hireGroupUpGrade.RowVersion = 0; hireGroupUpGrade.RecLastUpdatedBy = "Cares"; hireGroupUpGrade.IsReadOnly = false; hireGroupUpGrade.IsDeleted = false; hireGroupUpGrade.IsPrivate = false; hireGroupUpGrade.IsActive = false; hireGroupUpGrade.HireGroupId = hireGroup.HireGroupId; hireGroupUpGrade.AllowedHireGroupId = hireGroupUpGrade.AllowedHireGroupId; hireGroupDbVersion.HireGroupUpGrades.Add(hireGroupUpGrade); } } } //find missing Hire Group Up Garde items List <HireGroupUpGrade> missingHireGroupUpGradeItems = new List <HireGroupUpGrade>(); foreach (HireGroupUpGrade dbversionHireGroupUpGradeItem in hireGroupDbVersion.HireGroupUpGrades) { if (hireGroup.HireGroupUpGrades != null && hireGroup.HireGroupUpGrades.All(x => x.HireGroupUpGradeId != dbversionHireGroupUpGradeItem.HireGroupUpGradeId)) { missingHireGroupUpGradeItems.Add(dbversionHireGroupUpGradeItem); } if (hireGroup.HireGroupUpGrades == null) { missingHireGroupUpGradeItems.Add(dbversionHireGroupUpGradeItem); } } //remove missing Hire Group Up Grade items foreach (HireGroupUpGrade missingHireGroupUpGrade in missingHireGroupUpGradeItems) { HireGroupUpGrade dbVersionHireGroupDetailItem = hireGroupDbVersion.HireGroupUpGrades.First(x => x.HireGroupUpGradeId == missingHireGroupUpGrade.HireGroupUpGradeId); if (dbVersionHireGroupDetailItem.HireGroupUpGradeId > 0) { hireGroupDbVersion.HireGroupUpGrades.Remove(dbVersionHireGroupDetailItem); hireGroupUpGradeRepository.Delete(dbVersionHireGroupDetailItem); } } #endregion } hireGroupRepository.SaveChanges(); var hirGroup = hireGroupRepository.Find(hireGroup.HireGroupId); hireGroupRepository.LoadDependencies(hirGroup); return(hirGroup); }
/// <summary> /// Delete Hire Group /// </summary> /// <param name="instance"></param> public void DeleteHireGroup(HireGroup instance) { hireGroupRepository.Delete(instance); hireGroupRepository.SaveChanges(); }