Exemplo n.º 1
0
        //public async Task<OS_TaskQualificationTemplate_Dto> AddQualificationTemplate(OS_TaskQualificationTemplate taskQualificationTemplate)
        //{
        //    return ObjectMapper.Map<OS_TaskQualificationTemplate, OS_TaskQualificationTemplate_Dto>(await QualificationsRepository.InsertAsync(taskQualificationTemplate));
        //}
        //public async Task<OS_TaskQualificationTemplate_Dto> AddQualificationTemplate(OS_TaskQualificationTemplate_Dto taskQualificationTemplate)
        //{
        //    OS_TaskQualificationTemplate toAdd = ObjectMapper.Map<OS_TaskQualificationTemplate_Dto, OS_TaskQualificationTemplate>(taskQualificationTemplate);
        //    return ObjectMapper.Map<OS_TaskQualificationTemplate, OS_TaskQualificationTemplate_Dto>(await QualificationsRepository.InsertAsync(toAdd));
        //}

        public async Task <OS_TaskSkillTemplate_Dto> AddTaskSkill(OS_TaskSkillTemplate functionSkillTemplate)
        {
            return(ObjectMapper.Map <OS_TaskSkillTemplate, OS_TaskSkillTemplate_Dto>(await SkillsRepository.InsertAsync(functionSkillTemplate)));
        }
Exemplo n.º 2
0
        public async Task <OS_TaskSkillTemplate_Dto> AddTaskSkillTemplate(OS_TaskSkillTemplate_Dto functionSkillTemplate)
        {
            OS_TaskSkillTemplate toAdd = ObjectMapper.Map <OS_TaskSkillTemplate_Dto, OS_TaskSkillTemplate>(functionSkillTemplate);

            return(ObjectMapper.Map <OS_TaskSkillTemplate, OS_TaskSkillTemplate_Dto>(await SkillsRepository.InsertAsync(toAdd)));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostTaskTemplate()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var FormData = Request.Form;

                    OS_TaskTemplate_Dto taskTemplate_Dto = JsonSerializer.Deserialize <OS_TaskTemplate_Dto>(FormData["info"]);

                    bool IsEditing = taskTemplate_Dto.Id > 0;
                    if (IsEditing)
                    {
                        OS_TaskTemplate curTaskTemplate = await OS_TaskTemplateAppService.Repository.GetAsync(taskTemplate_Dto.Id);

                        if (AuditingManager.Current != null)
                        {
                            EntityChangeInfo entityChangeInfo = new EntityChangeInfo();

                            entityChangeInfo.EntityId           = taskTemplate_Dto.Id.ToString();
                            entityChangeInfo.EntityTenantId     = taskTemplate_Dto.TenantId;
                            entityChangeInfo.ChangeTime         = DateTime.Now;
                            entityChangeInfo.ChangeType         = EntityChangeType.Updated;
                            entityChangeInfo.EntityTypeFullName = typeof(OS_TaskTemplate).FullName;

                            entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>();
                            List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>();
                            var auditProps = typeof(OS_TaskTemplate).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList();

                            OS_TaskTemplate mappedInput = ObjectMapper.Map <OS_TaskTemplate_Dto, OS_TaskTemplate>(taskTemplate_Dto);
                            foreach (var prop in auditProps)
                            {
                                EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo();
                                object origVal = prop.GetValue(curTaskTemplate);
                                propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString();
                                object newVal = prop.GetValue(mappedInput);
                                propertyChange.NewValue = newVal == null ? "" : newVal.ToString();
                                if (propertyChange.OriginalValue == propertyChange.NewValue)
                                {
                                    continue;
                                }

                                propertyChange.PropertyName = prop.Name;

                                if (prop.Name.EndsWith("Id"))
                                {
                                    try
                                    {
                                        string valuePropName = prop.Name.TrimEnd('d', 'I');
                                        propertyChange.PropertyName = valuePropName;

                                        var valueProp = typeof(OS_TaskTemplate).GetProperty(valuePropName);

                                        DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(taskTemplate_Dto);
                                        if (_origValObj == null)
                                        {
                                            _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal);
                                        }
                                        string _origVal = _origValObj.Value;
                                        propertyChange.OriginalValue = origVal == null ? "" : _origVal;
                                        DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput);
                                        if (_newValObj == null)
                                        {
                                            _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal);
                                        }
                                        string _newVal = _newValObj.Value;
                                        propertyChange.NewValue = _newValObj == null ? "" : _newVal;
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }

                                propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName;

                                entityChangeInfo.PropertyChanges.Add(propertyChange);
                            }

                            #region ExtraProperties
                            //List<EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List<EmployeeExtraPropertyHistory>();
                            //if (departmentTemplate_Dto.ExtraProperties != curTaskTemplate.ExtraProperties)
                            //{
                            //    //GeneralInfo oldGeneralInfo = department.GetProperty<GeneralInfo>("generalInfo");
                            //    //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>();
                            //    //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList();
                            //    //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList();
                            //    //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList();
                            //    //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList();
                            //    //for (int i = 0; i < NewPhysicalIds.Count; i++)
                            //    //{
                            //    //    PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i];

                            //    //    EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created");
                            //    //    physicalIdsHistory.Add(newPhIdHistory);
                            //    //}
                            //    //for (int i = 0; i < UpdatedPhysicalIds.Count; i++)
                            //    //{
                            //    //    PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i];
                            //    //    PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id);

                            //    //    EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated");
                            //    //    foreach (var prop in generalInfoPhysicalIdAuditProps)
                            //    //    {
                            //    //        updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>();

                            //    //        EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange();

                            //    //        object origVal = prop.GetValue(oldPhId);
                            //    //        propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString();
                            //    //        object newVal = prop.GetValue(curPhId);
                            //    //        propertyChange.NewValue = newVal == null ? "" : newVal.ToString();
                            //    //        if (propertyChange.OriginalValue == propertyChange.NewValue) continue;

                            //    //        propertyChange.PropertyName = prop.Name;

                            //    //        if (prop.Name.EndsWith("Id"))
                            //    //        {
                            //    //            try
                            //    //            {
                            //    //                string valuePropName = prop.Name.TrimEnd('d', 'I');
                            //    //                propertyChange.PropertyName = valuePropName;

                            //    //                var valueProp = typeof(PhysicalID).GetProperty(valuePropName);

                            //    //                DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId);
                            //    //                if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal);
                            //    //                string _origVal = _origValObj.Value;
                            //    //                propertyChange.OriginalValue = origVal == null ? "" : _origVal;
                            //    //                DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId);
                            //    //                if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal);
                            //    //                string _newVal = _newValObj.Value;
                            //    //                propertyChange.NewValue = _newValObj == null ? "" : _newVal;
                            //    //            }
                            //    //            catch (Exception ex)
                            //    //            {

                            //    //            }
                            //    //        }

                            //    //        propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName;

                            //    //        updatedPhIdHistory.PropertyChanges.Add(propertyChange);
                            //    //    }
                            //    //    physicalIdsHistory.Add(updatedPhIdHistory);
                            //    //}
                            //    //for (int i = 0; i < DeletedPhysicalIds.Count; i++)
                            //    //{
                            //    //    PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i];

                            //    //    EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted");
                            //    //    physicalIdsHistory.Add(deletedPhIdHistory);
                            //    //}

                            //    entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories);
                            //}
                            #endregion

                            AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo);
                        }

                        curTaskTemplate.Name                 = taskTemplate_Dto.Name;
                        curTaskTemplate.NameLocalized        = taskTemplate_Dto.NameLocalized;
                        curTaskTemplate.Code                 = taskTemplate_Dto.Code;
                        curTaskTemplate.ValidityFromDate     = taskTemplate_Dto.ValidityFromDate;
                        curTaskTemplate.ValidityToDate       = taskTemplate_Dto.ValidityToDate;
                        curTaskTemplate.Description          = taskTemplate_Dto.Description;
                        curTaskTemplate.DoesKPI              = taskTemplate_Dto.DoesKPI;
                        curTaskTemplate.ReviewPeriod         = taskTemplate_Dto.ReviewPeriod;
                        curTaskTemplate.ReviewPeriodDays     = taskTemplate_Dto.ReviewPeriodDays;
                        curTaskTemplate.WorkflowLinkability  = taskTemplate_Dto.WorkflowLinkability;
                        curTaskTemplate.CompensationMatrix   = null;
                        curTaskTemplate.CompensationMatrixId = taskTemplate_Dto.CompensationMatrixId;

                        #region Child Entities
                        OS_TaskSkillTemplate_Dto[] taskSkills = taskTemplate_Dto.TaskSkillTemplates.ToArray();
                        int[]      curTaskSkillsIds           = curTaskTemplate.TaskSkillTemplates != null && curTaskTemplate.TaskSkillTemplates.Count > 0 ? curTaskTemplate.TaskSkillTemplates.Select(x => x.SkillTemplate.Id).ToArray() : new int[0];
                        List <int> toDeleteSkills             = new List <int>();
                        for (int i = 0; i < curTaskSkillsIds.Length; i++)
                        {
                            OS_TaskSkillTemplate curTaskSkill = curTaskTemplate.TaskSkillTemplates.First(x => x.SkillTemplateId == curTaskSkillsIds[i]);
                            if (!taskSkills.Any(x => x.SkillTemplate.Id == curTaskSkillsIds[i]))
                            {
                                curTaskTemplate.TaskSkillTemplates.Remove(curTaskTemplate.TaskSkillTemplates.First(x => x.SkillTemplateId == curTaskSkillsIds[i]));
                                toDeleteSkills.Add(curTaskSkillsIds[i]);
                            }
                        }
                        for (int i = 0; i < taskSkills.Length; i++)
                        {
                            if (!curTaskTemplate.TaskSkillTemplates.Any(x => x.SkillTemplateId == taskSkills[i].SkillTemplate.Id))
                            {
                                curTaskTemplate.TaskSkillTemplates.Add(new OS_TaskSkillTemplate()
                                {
                                    SkillTemplateId = taskSkills[i].SkillTemplate.Id
                                });
                            }
                            else
                            {
                                var _taskSkill = curTaskTemplate.TaskSkillTemplates.First(x => x.SkillTemplateId == taskSkills[i].SkillTemplate.Id);
                                //_taskLoc.TaskValidityStart = posTasks[i].TaskValidityStart;
                                //_taskLoc.TaskValidityEnd = posTasks[i].TaskValidityEnd;
                                //_taskLoc.Name = posTasks[i].Name;

                                //curTask.TaskSkillTemplates.Remove(curTask.TaskSkillTemplates.First(x => x.TaskTemplateId == _taskLoc.TaskTemplateId));
                                await OS_TaskTemplateAppService.SkillsRepository.UpdateAsync(_taskSkill);
                            }
                        }
                        for (int i = 0; i < toDeleteSkills.Count; i++)
                        {
                            await OS_TaskTemplateAppService.SkillsRepository.DeleteAsync(x => x.SkillTemplateId == toDeleteSkills[i]);
                        }

                        OS_TaskAcademiaTemplate_Dto[] taskAcademia = taskTemplate_Dto.TaskAcademiaTemplates.ToArray();
                        int[]      curTaskAcademiaIds = curTaskTemplate.TaskAcademiaTemplates != null && curTaskTemplate.TaskAcademiaTemplates.Count > 0 ? curTaskTemplate.TaskAcademiaTemplates.Select(x => x.AcademiaTemplate.Id).ToArray() : new int[0];
                        List <int> toDeleteAcademia   = new List <int>();
                        for (int i = 0; i < curTaskAcademiaIds.Length; i++)
                        {
                            OS_TaskAcademiaTemplate curTaskAcademia = curTaskTemplate.TaskAcademiaTemplates.First(x => x.AcademiaTemplateId == curTaskAcademiaIds[i]);
                            if (!taskAcademia.Any(x => x.AcademiaTemplate.Id == curTaskAcademiaIds[i]))
                            {
                                curTaskTemplate.TaskAcademiaTemplates.Remove(curTaskTemplate.TaskAcademiaTemplates.First(x => x.AcademiaTemplateId == curTaskAcademiaIds[i]));
                                toDeleteSkills.Add(curTaskAcademiaIds[i]);
                            }
                        }
                        for (int i = 0; i < taskAcademia.Length; i++)
                        {
                            if (!curTaskTemplate.TaskAcademiaTemplates.Any(x => x.AcademiaTemplateId == taskAcademia[i].AcademiaTemplate.Id))
                            {
                                curTaskTemplate.TaskAcademiaTemplates.Add(new OS_TaskAcademiaTemplate()
                                {
                                    AcademiaTemplateId = taskAcademia[i].AcademiaTemplate.Id
                                });
                            }
                            else
                            {
                                var _taskAcademia = curTaskTemplate.TaskAcademiaTemplates.First(x => x.AcademiaTemplateId == taskAcademia[i].AcademiaTemplate.Id);
                                //_taskLoc.TaskValidityStart = posTasks[i].TaskValidityStart;
                                //_taskLoc.TaskValidityEnd = posTasks[i].TaskValidityEnd;
                                //_taskLoc.Name = posTasks[i].Name;

                                //curTask.TaskAcademiaTemplates.Remove(curTask.TaskAcademiaTemplates.First(x => x.TaskTemplateId == _taskLoc.TaskTemplateId));
                                await OS_TaskTemplateAppService.AcademiaRepository.UpdateAsync(_taskAcademia);
                            }
                        }
                        for (int i = 0; i < toDeleteAcademia.Count; i++)
                        {
                            await OS_TaskTemplateAppService.AcademiaRepository.DeleteAsync(x => x.AcademiaTemplateId == toDeleteAcademia[i]);
                        }
                        #endregion

                        OS_TaskTemplate_Dto updated = ObjectMapper.Map <OS_TaskTemplate, OS_TaskTemplate_Dto>(await OS_TaskTemplateAppService.Repository.UpdateAsync(curTaskTemplate));
                        updated = ObjectMapper.Map <OS_TaskTemplate, OS_TaskTemplate_Dto>(await OS_TaskTemplateAppService.Repository.GetAsync(updated.Id));

                        return(StatusCode(200, updated));
                    }
                    else
                    {
                        taskTemplate_Dto.Id = 0;
                        if (taskTemplate_Dto.TaskSkillTemplates != null)
                        {
                            taskTemplate_Dto.TaskSkillTemplates.ForEach(x => { x.Id = 0; x.SkillTemplateId = x.SkillTemplate.Id; x.SkillTemplate = null; });
                        }
                        if (taskTemplate_Dto.TaskAcademiaTemplates != null)
                        {
                            taskTemplate_Dto.TaskAcademiaTemplates.ForEach(x => { x.Id = 0; x.AcademiaTemplateId = x.AcademiaTemplate.Id; x.AcademiaTemplate = null; });
                        }
                        taskTemplate_Dto.CompensationMatrix = null;

                        OS_TaskTemplate_Dto added = await OS_TaskTemplateAppService.CreateAsync(taskTemplate_Dto);

                        added = await OS_TaskTemplateAppService.GetAsync(added.Id);

                        if (AuditingManager.Current != null)
                        {
                            EntityChangeInfo entityChangeInfo = new EntityChangeInfo();
                            entityChangeInfo.EntityId           = added.Id.ToString();
                            entityChangeInfo.EntityTenantId     = added.TenantId;
                            entityChangeInfo.ChangeTime         = DateTime.Now;
                            entityChangeInfo.ChangeType         = EntityChangeType.Created;
                            entityChangeInfo.EntityTypeFullName = typeof(OS_TaskTemplate).FullName;

                            AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo);
                        }

                        return(StatusCode(200, added));
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return(StatusCode(500));
        }