Exemplo n.º 1
0
        public int SavePerformanceReviewSetting(PerformanceReviewSettingModel model)
        {
            var performanceReviewSetting = Mapper.DynamicMap <tblPerformanceReviewSetting>(model);

            _performanceReviewSettingRepository.Add(performanceReviewSetting);
            return(_performanceReviewSettingRepository.SaveChanges());
        }
        // POST api/<controller>
        public int Post([FromBody] PerformanceReviewSettingModel model)
        {
            if (model != null)
            {
                if (model.PerformanceReviewID == 0)
                {
                    model.CreatedBy   = base.UserName;
                    model.CreatedDate = DateTime.Now;
                    model.CompanyID   = base.CompanyId;
                    model.Status      = true;
                    foreach (var item in model.tblPerformanceScores)
                    {
                        item.Status = true;
                    }

                    foreach (var item in model.tblPerformanceSegments)
                    {
                        foreach (var subItem in item.tblPerformaceSegmentQuestions)
                        {
                            subItem.CreatedDate = DateTime.Now;
                            subItem.CreatedBy   = base.UserName;
                        }
                    }

                    return(_performanceReviewSettingService.SavePerformanceReviewSetting(model));
                }
                else
                {
                    model.LastUpdatedBy   = base.UserName;
                    model.LastUpdatedDate = DateTime.Now;
                    model.CompanyID       = base.CompanyId;
                    model.Status          = true;
                    foreach (var item in model.tblPerformanceSegments)
                    {
                        //item.UpdatedDate = DateTime.Now;
                        //item.UpdatedBy = base.UserName;
                        foreach (var subItem in item.tblPerformaceSegmentQuestions)
                        {
                            subItem.UpdatedDate = DateTime.Now;
                            subItem.UpdatedBy   = base.UserName;
                        }
                    }

                    return(_performanceReviewSettingService.UpdatePerformanceReviewSetting(model));
                }
            }

            return(0);
        }
Exemplo n.º 3
0
        public int UpdatePerformanceReviewSetting(PerformanceReviewSettingModel model)
        {
            tblPerformanceReviewSetting performanceReviewSettingEntity = _performanceReviewSettingRepository
                                                                         .GetPerformanceSettingsById(model.PerformanceReviewID);

            if (performanceReviewSettingEntity != null)
            {
                //Mapper.CreateMap<PerformanceReviewSettingModel, tblPerformanceReviewSetting>()
                //    .ForMember(dest => dest.PerformanceReviewID, opt => opt.Ignore()); // ignore primary key while update/delete
                //tblPerformanceReviewSetting obj = (tblPerformanceReviewSetting)Mapper.Map(model, performanceReviewSettingEntity);

                performanceReviewSettingEntity.ReviewTitle          = model.ReviewTitle;
                performanceReviewSettingEntity.ReviewCompletionDate = model.ReviewCompletionDate;
                performanceReviewSettingEntity.CompanyID            = model.CompanyID;
                performanceReviewSettingEntity.LocationID           = model.LocationID;
                performanceReviewSettingEntity.DepartmentID         = model.DepartmentID;
                performanceReviewSettingEntity.JobRoleID            = model.JobRoleID;
                performanceReviewSettingEntity.EmploymentTypeID     = model.EmploymentTypeID;
                performanceReviewSettingEntity.LengthOfService      = model.LengthOfService;
                performanceReviewSettingEntity.CreatedBy            = model.CreatedBy;
                performanceReviewSettingEntity.CreatedDate          = model.CreatedDate;
                performanceReviewSettingEntity.LastUpdatedBy        = model.LastUpdatedBy;
                performanceReviewSettingEntity.LastUpdatedDate      = model.LastUpdatedDate;

                List <PerformanceSegmentModel>        segments  = new List <PerformanceSegmentModel>();
                List <PerformaceSegmentQuestionModel> Questions = new List <PerformaceSegmentQuestionModel>();
                for (int i = 0; i < model.tblPerformanceSegments.Count; i++)
                {
                    if (model.tblPerformanceSegments[i].PerformanceSegmentID == 0)
                    {
                        model.tblPerformanceSegments[i].PerformanceReviewID = model.PerformanceReviewID;
                        //PerformanceSegmentModel segm = new PerformanceSegmentModel();
                        //segm.PerformanceReviewID = model.tblPerformanceSegments[i].PerformanceReviewID;
                        //segm.SegmentDescription = model.tblPerformanceSegments[i].SegmentDescription;
                        ////segm.CreatedDate = DateTime.Now;
                        ////segm.CreatedBy = model.CreatedBy;
                        //segm.SegmentName = model.tblPerformanceSegments[i].SegmentName;
                        model.tblPerformanceSegments[i].tblPerformaceSegmentQuestions = new List <PerformaceSegmentQuestionModel>();
                        segments.Add(model.tblPerformanceSegments[i]);
                    }
                    else
                    {
                        performanceReviewSettingEntity.tblPerformanceSegments[i].SegmentName        = model.tblPerformanceSegments[i].SegmentName;
                        performanceReviewSettingEntity.tblPerformanceSegments[i].SegmentDescription = model.tblPerformanceSegments[i].SegmentDescription;
                        // question updates
                        for (int j = 0; j < model.tblPerformanceSegments[i].tblPerformaceSegmentQuestions.Count; j++)
                        {
                            if (model.tblPerformanceSegments[i].tblPerformaceSegmentQuestions[j].PerformanceQuestionID == 0)
                            {
                                // while updating adding aditional record for question
                                model.tblPerformanceSegments[i].tblPerformaceSegmentQuestions[j].PerformanceSegmentID =
                                    model.tblPerformanceSegments[i].PerformanceSegmentID;
                                Questions.Add(model.tblPerformanceSegments[i].tblPerformaceSegmentQuestions[j]);
                            }
                            else
                            {
                                performanceReviewSettingEntity.tblPerformanceSegments[i]
                                .tblPerformaceSegmentQuestions[j].Question =
                                    model.tblPerformanceSegments[i].tblPerformaceSegmentQuestions[j].Question;
                                performanceReviewSettingEntity.tblPerformanceSegments[i]
                                .tblPerformaceSegmentQuestions[j].HelpText =
                                    model.tblPerformanceSegments[i].tblPerformaceSegmentQuestions[j].HelpText;
                            }
                        }
                    }
                }

                _performanceReviewSettingRepository.Update(performanceReviewSettingEntity);
                _performanceReviewSettingRepository.SaveChanges();
                if (segments.Count > 0)
                {
                    foreach (var seg in segments)
                    {
                        //var entityPerformanceSegment = Mapper.DynamicMap<tblPerformanceSegment>(seg);
                        ////var entityPerformanceSegment = new tblPerformanceSegment {SegmentDescription = "sdfsdfsd", SegmentName = "sfsdfsdfsf"};
                        //entityPerformanceSegment.Status = true;

                        //entityPerformanceSegment.CreatedDate = DateTime.Now;
                        ////entityPerformanceSegment.tblPerformanceReviewSetting= new tblPerformanceReviewSetting();
                        //_performanceSegmentRepository.Add(entityPerformanceSegment);
                        //_performanceSegmentRepository.SaveChanges();
                    }

                    var entityPerformanceSegments = Mapper.DynamicMap <List <tblPerformanceSegment> >(segments);
                    _performanceSegmentRepository.BulkSegmentSave(entityPerformanceSegments);
                }

                if (segments.Count == 0 && Questions.Count > 0)
                {
                    // TODO insert question into question table
                    foreach (var question in Questions)
                    {
                        question.CreatedDate = DateTime.Now;
                        question.Status      = true;
                        var entityPerformanceQuestion = Mapper.DynamicMap <tblPerformaceSegmentQuestion>(question);
                        //entityPerformanceQuestion.tblPerformanceSegment = new tblPerformanceSegment();
                        _performancesegmentQuestionRepository.Add(entityPerformanceQuestion);
                        _performancesegmentQuestionRepository.SaveChanges();
                    }
                }

                return(1);
            }

            return(0);
        }
 // PUT api/<controller>/5
 public int Put([FromBody] PerformanceReviewSettingModel model)
 {
     return(_performanceReviewSettingService.UpdatePerformanceReviewSetting(model));
 }