Beispiel #1
0
        public int DeleteByProfileIdAndPersonnelId(int profileId, int personnelId)
        {
            int result = 0;

            using (AppDBContext dbContext = new AppDBContext(_config))
            {
                ProfilePersonnel record = dbContext.ProfilePersonnel.Where(pd => pd.ProfileId == profileId && pd.PersonnelId == personnelId).AsNoTracking().SingleOrDefault();
                dbContext.Entry(record).State = EntityState.Deleted;
                result = dbContext.SaveChanges();
            }

            return(result);
        }
Beispiel #2
0
        public int Add(ProfilePersonnel record)
        {
            int result = 0;

            using (AppDBContext dbContext = new AppDBContext(_config))
            {
                ProfilePersonnel existrecord = dbContext.ProfilePersonnel.Where(pd => pd.ProfileId == record.ProfileId && pd.PersonnelId == record.PersonnelId).FirstOrDefault();
                if (existrecord == null)
                {
                    dbContext.Entry(record).State = EntityState.Added;
                    result = dbContext.SaveChanges();
                }
            }

            return(result);
        }
        public ActionResult BatchEdit(BatchEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ProfileSelectList = GetProfileSelectList();

                if (model.ProfileId.HasValue)
                {
                    if (model.PersonnelList.Filter == null)
                    {
                        model.PersonnelList.Filter = new DefinedPersonnelListFilterViewModel();
                    }
                    if (model.PersonnelWhichIsNotIncludeList.Filter == null)
                    {
                        model.PersonnelWhichIsNotIncludeList.Filter = new UndefinedPersonnelListFilterViewModel();
                    }

                    if (!model.PersonnelList.CurrentPage.HasValue)
                    {
                        model.PersonnelList.CurrentPage = 1;
                    }

                    if (!model.PersonnelList.PageSize.HasValue)
                    {
                        model.PersonnelList.PageSize = 10;
                    }

                    if (!model.PersonnelWhichIsNotIncludeList.CurrentPage.HasValue)
                    {
                        model.PersonnelWhichIsNotIncludeList.CurrentPage = 1;
                    }

                    if (!model.PersonnelWhichIsNotIncludeList.PageSize.HasValue)
                    {
                        model.PersonnelWhichIsNotIncludeList.PageSize = 10;
                    }

                    ProfilePersonnelSearchFilter profilePersonnelSearchFilter = new ProfilePersonnelSearchFilter();
                    profilePersonnelSearchFilter.Filter_ProfileId          = model.ProfileId.Value;
                    profilePersonnelSearchFilter.CurrentPage               = model.PersonnelList.CurrentPage.HasValue ? model.PersonnelList.CurrentPage.Value : 1;
                    profilePersonnelSearchFilter.PageSize                  = model.PersonnelList.PageSize.HasValue ? model.PersonnelList.PageSize.Value : 10;
                    profilePersonnelSearchFilter.SortOn                    = model.PersonnelList.SortOn;
                    profilePersonnelSearchFilter.SortDirection             = model.PersonnelList.SortDirection;
                    profilePersonnelSearchFilter.Filter_Personnel_Name     = model.PersonnelList.Filter.Filter_Personnel_Name;
                    profilePersonnelSearchFilter.Filter_Personnel_LastName = model.PersonnelList.Filter.Filter_Personnel_LastName;

                    ProfilePersonnelSearchFilter profilePersonnelWhichIsNotIncludeListSearchFilter = new ProfilePersonnelSearchFilter();
                    profilePersonnelWhichIsNotIncludeListSearchFilter.Filter_ProfileId          = model.ProfileId.Value;
                    profilePersonnelWhichIsNotIncludeListSearchFilter.CurrentPage               = model.PersonnelWhichIsNotIncludeList.CurrentPage.HasValue ? model.PersonnelWhichIsNotIncludeList.CurrentPage.Value : 1;
                    profilePersonnelWhichIsNotIncludeListSearchFilter.PageSize                  = model.PersonnelWhichIsNotIncludeList.PageSize.HasValue ? model.PersonnelWhichIsNotIncludeList.PageSize.Value : 10;
                    profilePersonnelWhichIsNotIncludeListSearchFilter.SortOn                    = model.PersonnelWhichIsNotIncludeList.SortOn;
                    profilePersonnelWhichIsNotIncludeListSearchFilter.SortDirection             = model.PersonnelWhichIsNotIncludeList.SortDirection;
                    profilePersonnelWhichIsNotIncludeListSearchFilter.Filter_Personnel_Name     = model.PersonnelWhichIsNotIncludeList.Filter.Filter_Personnel_Name;
                    profilePersonnelWhichIsNotIncludeListSearchFilter.Filter_Personnel_LastName = model.PersonnelWhichIsNotIncludeList.Filter.Filter_Personnel_LastName;

                    model.PersonnelList.DataList = GetAllEmployeeByProfileId(profilePersonnelSearchFilter);
                    model.PersonnelWhichIsNotIncludeList.DataList = GetAllEmployeeByProfileIdWhichIsNotIncluded(profilePersonnelWhichIsNotIncludeListSearchFilter);
                }
                else
                {
                    model.PersonnelList             = new DefinedPersonnelListViewModel();
                    model.PersonnelList.Filter      = new DefinedPersonnelListFilterViewModel();
                    model.PersonnelList.DataList    = new Business.Models.PaginatedList <PersonnelCheckViewModel>(new List <PersonnelCheckViewModel>(), 0, 1, 10, "", "");
                    model.PersonnelList.CurrentPage = 1;
                    model.PersonnelList.PageSize    = 10;

                    model.PersonnelWhichIsNotIncludeList             = new UndefinedPersonnelListViewModel();
                    model.PersonnelWhichIsNotIncludeList.Filter      = new UndefinedPersonnelListFilterViewModel();
                    model.PersonnelWhichIsNotIncludeList.DataList    = new Business.Models.PaginatedList <PersonnelCheckViewModel>(new List <PersonnelCheckViewModel>(), 0, 1, 10, "", "");
                    model.PersonnelWhichIsNotIncludeList.CurrentPage = 1;
                    model.PersonnelWhichIsNotIncludeList.PageSize    = 10;
                }
                return(View(model));
            }

            if (model.SubmitType == "Add")
            {
                if (model.PersonnelWhichIsNotIncludeList.DataList != null && model.ProfileId.HasValue)
                {
                    ModelState.Clear();
                    List <PersonnelCheckViewModel> records = model.PersonnelWhichIsNotIncludeList.DataList.Items.Where(x => x.Checked == true).ToList();
                    if (records != null)
                    {
                        foreach (var item in records)
                        {
                            ProfilePersonnel profilePersonnel = new ProfilePersonnel();
                            profilePersonnel.PersonnelId = item.Id;
                            profilePersonnel.ProfileId   = model.ProfileId.Value;
                            _profilePersonnelService.Add(profilePersonnel);
                        }
                    }
                }
            }
            if (model.SubmitType == "Delete")
            {
                if (model.PersonnelList.DataList != null && model.ProfileId.HasValue)
                {
                    ModelState.Clear();
                    List <PersonnelCheckViewModel> record = model.PersonnelList.DataList.Items.Where(x => x.Checked == true).ToList();
                    if (record != null)
                    {
                        foreach (var item in record)
                        {
                            var apiResponseModel = _profilePersonnelService.DeleteByProfileIdAndEmployeeId(model.ProfileId.Value, item.Id);
                        }
                    }
                }
            }

            model.ProfileSelectList = GetProfileSelectList();
            if (model.ProfileId.HasValue)
            {
                if (model.PersonnelList.Filter == null)
                {
                    model.PersonnelList.Filter = new DefinedPersonnelListFilterViewModel();
                }
                if (model.PersonnelWhichIsNotIncludeList.Filter == null)
                {
                    model.PersonnelWhichIsNotIncludeList.Filter = new UndefinedPersonnelListFilterViewModel();
                }

                if (!model.PersonnelList.CurrentPage.HasValue)
                {
                    model.PersonnelList.CurrentPage = 1;
                }

                if (!model.PersonnelList.PageSize.HasValue)
                {
                    model.PersonnelList.PageSize = 10;
                }

                if (!model.PersonnelWhichIsNotIncludeList.CurrentPage.HasValue)
                {
                    model.PersonnelWhichIsNotIncludeList.CurrentPage = 1;
                }

                if (!model.PersonnelWhichIsNotIncludeList.PageSize.HasValue)
                {
                    model.PersonnelWhichIsNotIncludeList.PageSize = 10;
                }


                ProfilePersonnelSearchFilter profilePersonnelSearchFilter = new ProfilePersonnelSearchFilter();
                profilePersonnelSearchFilter.Filter_ProfileId          = model.ProfileId.Value;
                profilePersonnelSearchFilter.CurrentPage               = model.PersonnelList.CurrentPage.HasValue ? model.PersonnelList.CurrentPage.Value : 1;
                profilePersonnelSearchFilter.PageSize                  = model.PersonnelList.PageSize.HasValue ? model.PersonnelList.PageSize.Value : 10;
                profilePersonnelSearchFilter.SortOn                    = model.PersonnelList.SortOn;
                profilePersonnelSearchFilter.SortDirection             = model.PersonnelList.SortDirection;
                profilePersonnelSearchFilter.Filter_Personnel_Name     = model.PersonnelList.Filter.Filter_Personnel_Name;
                profilePersonnelSearchFilter.Filter_Personnel_LastName = model.PersonnelList.Filter.Filter_Personnel_LastName;

                ProfilePersonnelSearchFilter profilePersonnelWhichIsNotIncludeListSearchFilter = new ProfilePersonnelSearchFilter();
                profilePersonnelWhichIsNotIncludeListSearchFilter.Filter_ProfileId          = model.ProfileId.Value;
                profilePersonnelWhichIsNotIncludeListSearchFilter.CurrentPage               = model.PersonnelWhichIsNotIncludeList.CurrentPage.HasValue ? model.PersonnelWhichIsNotIncludeList.CurrentPage.Value : 1;
                profilePersonnelWhichIsNotIncludeListSearchFilter.PageSize                  = model.PersonnelWhichIsNotIncludeList.PageSize.HasValue ? model.PersonnelWhichIsNotIncludeList.PageSize.Value : 10;
                profilePersonnelWhichIsNotIncludeListSearchFilter.SortOn                    = model.PersonnelWhichIsNotIncludeList.SortOn;
                profilePersonnelWhichIsNotIncludeListSearchFilter.SortDirection             = model.PersonnelWhichIsNotIncludeList.SortDirection;
                profilePersonnelWhichIsNotIncludeListSearchFilter.Filter_Personnel_Name     = model.PersonnelWhichIsNotIncludeList.Filter.Filter_Personnel_Name;
                profilePersonnelWhichIsNotIncludeListSearchFilter.Filter_Personnel_LastName = model.PersonnelWhichIsNotIncludeList.Filter.Filter_Personnel_LastName;

                model.PersonnelList.DataList = GetAllEmployeeByProfileId(profilePersonnelSearchFilter);
                model.PersonnelWhichIsNotIncludeList.DataList = GetAllEmployeeByProfileIdWhichIsNotIncluded(profilePersonnelWhichIsNotIncludeListSearchFilter);

                if (model.PersonnelList.DataList == null || model.PersonnelList.DataList.Items == null)
                {
                    model.PersonnelList.DataList = new Business.Models.PaginatedList <PersonnelCheckViewModel>(new List <PersonnelCheckViewModel>(), 0, 1, 10, "", "");
                }
                if (model.PersonnelWhichIsNotIncludeList.DataList == null || model.PersonnelWhichIsNotIncludeList.DataList.Items == null)
                {
                    model.PersonnelWhichIsNotIncludeList.DataList = new Business.Models.PaginatedList <PersonnelCheckViewModel>(new List <PersonnelCheckViewModel>(), 0, 1, 10, "", "");
                }
            }
            else
            {
                model.PersonnelList             = new DefinedPersonnelListViewModel();
                model.PersonnelList.Filter      = new DefinedPersonnelListFilterViewModel();
                model.PersonnelList.DataList    = new Business.Models.PaginatedList <PersonnelCheckViewModel>(new List <PersonnelCheckViewModel>(), 0, 1, 10, "", "");
                model.PersonnelList.CurrentPage = 1;
                model.PersonnelList.PageSize    = 10;

                model.PersonnelWhichIsNotIncludeList             = new UndefinedPersonnelListViewModel();
                model.PersonnelWhichIsNotIncludeList.Filter      = new UndefinedPersonnelListFilterViewModel();
                model.PersonnelWhichIsNotIncludeList.DataList    = new Business.Models.PaginatedList <PersonnelCheckViewModel>(new List <PersonnelCheckViewModel>(), 0, 1, 10, "", "");
                model.PersonnelWhichIsNotIncludeList.CurrentPage = 1;
                model.PersonnelWhichIsNotIncludeList.PageSize    = 10;
            }

            return(View(model));
        }