コード例 #1
0
        public ActionResult Edit(int id)
        {
            //find the existing PermissionRegion from database
            PermissionRegion PermissionRegion = permissionregionRepository.Find(id);

            //return editor view
            return(View(PermissionRegion));
        }
コード例 #2
0
        public ActionResult Create(int permissionId)
        {
            //create a new instance of PermissionRegion
            PermissionRegion PermissionRegion = new PermissionRegion();

            PermissionRegion.PermissionID = permissionId;
            //return view result
            return(View(PermissionRegion));
        }
コード例 #3
0
        public ActionResult DetailsAjax(int id)
        {
            PermissionRegion PermissionRegion = permissionregionRepository.Find(id);

            if (PermissionRegion == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Region not found"));
            }
            return(Content(this.RenderPartialViewToString(Constants.PartialViews.Details, PermissionRegion)));
        }
コード例 #4
0
        public ActionResult LoadJamatkhanaEditorAjax(int regionID, int permissionID)
        {
            PermissionRegion permissionregion = new PermissionRegion();

            if (IsRegionalAdministrator)
            {
                permissionregion.AllJamatkhanas = permissionjamatkhanaRepository.FindAllJamatkhanaByWordkerID(CurrentLoggedInWorker.ID, regionID).ToList();
            }
            else
            {
                permissionregion.AllJamatkhanas = jamatkhanaRepository.FindAllJamatkhanaByRegionID(regionID).ToList();
            }

            return(Content(this.RenderPartialViewToString("~/Areas/WorkerManagement/Views/Permission/_Jamatkhana.cshtml", permissionregion)));
        }
コード例 #5
0
        public ActionResult LoadSubProgramEditorAjax(int programID, int permissionID)
        {
            PermissionRegion permissionregion = new PermissionRegion();

            if (IsRegionalAdministrator)
            {
                //permissionregion.AllSubPrograms = subprogramRepository.FindAllByWordkerID(CurrentLoggedInWorker.ID, programID).ToList();
                permissionregion.AllSubPrograms = permissionsubprogamRepository.FindAllSubProgramByWordkerID(CurrentLoggedInWorker.ID, programID).ToList();
            }
            else
            {
                permissionregion.AllSubPrograms = subprogramRepository.FindAllByProgramID(programID).ToList();
            }

            return(Content(this.RenderPartialViewToString("~/Areas/WorkerManagement/Views/Permission/_SubProgram.cshtml", permissionregion)));
        }
コード例 #6
0
 public ActionResult Edit(PermissionRegion PermissionRegion, int workerId)
 {
     PermissionRegion.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
     try
     {
         //validate data
         if (ModelState.IsValid)
         {
             //call the repository function to save in database
             permissionregionRepository.InsertOrUpdate(PermissionRegion);
             permissionregionRepository.Save();
             //redirect to list page after successful operation
             return(RedirectToAction(Constants.Views.Index, new { workerId = workerId }));
         }
         else
         {
             foreach (var modelStateValue in ViewData.ModelState.Values)
             {
                 foreach (var error in modelStateValue.Errors)
                 {
                     PermissionRegion.ErrorMessage = error.ErrorMessage;
                     break;
                 }
                 if (PermissionRegion.ErrorMessage.IsNotNullOrEmpty())
                 {
                     break;
                 }
             }
         }
     }
     catch (CustomException ex)
     {
         PermissionRegion.ErrorMessage = ex.UserDefinedMessage;
     }
     catch (Exception ex)
     {
         ExceptionManager.Manage(ex);
         PermissionRegion.ErrorMessage = Constants.Messages.UnhandelledError;
     }
     //return view with error message if the operation is failed
     return(View(PermissionRegion));
 }
コード例 #7
0
        public ActionResult EditorAjax(int id, string permissionId)
        {
            PermissionRegion PermissionRegion = null;

            if (id > 0)
            {
                //find an existing PermissionRegion from database
                PermissionRegion = permissionregionRepository.Find(id);
                if (PermissionRegion == null)
                {
                    //throw an exception if id is provided but data does not exist in database
                    return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Region not found"));
                }
            }
            else
            {
                //create a new instance if id is not provided
                PermissionRegion = new PermissionRegion();
                PermissionRegion.PermissionID = permissionId.ToInteger(true);
            }
            if (IsRegionalAdministrator)
            {
                //PermissionRegion.AllSubPrograms = subprogramRepository.FindAllByWordkerID(CurrentLoggedInWorker.ID, 0).ToList();
                PermissionRegion.AllSubPrograms = permissionsubprogamRepository.FindAllSubProgramByWordkerID(CurrentLoggedInWorker.ID, PermissionRegion.ProgramID).ToList();
                PermissionRegion.AllJamatkhanas = permissionjamatkhanaRepository.FindAllJamatkhanaByWordkerID(CurrentLoggedInWorker.ID, PermissionRegion.RegionID).ToList();
            }
            else
            {
                PermissionRegion.AllSubPrograms = subprogramRepository.FindAllByProgramID(PermissionRegion.ProgramID).ToList();         // subprogramRepository.All.Where(item => item.IsActive == true && item.ProgramID == PermissionRegion.ProgramID).ToList();
                PermissionRegion.AllJamatkhanas = jamatkhanaRepository.FindAllJamatkhanaByRegionID(PermissionRegion.RegionID).ToList(); //jamatkhanaRepository.All.Where(item => item.IsActive == true && item.RegionID == PermissionRegion.RegionID).ToList();
            }

            PermissionRegion.AssignedSubPrograms = permissionsubprogamRepository.All.Where(item => item.PermissionRegionID == id).ToList();
            PermissionRegion.AssignedJamatkhanas = permissionjamatkhanaRepository.All.Where(item => item.PermissionRegionID == id).ToList();

            //ViewBag.Programs = programRepository.All.AsEnumerable().Select(o => new { ID = o.ID, Name = o.Name }).ToList();
            //return the html of editor to display on popup
            return(Content(this.RenderPartialViewToString("~/Areas/WorkerManagement/Views/Permission/_PermissionRegion.cshtml", PermissionRegion)));
        }
コード例 #8
0
        private void UpdateUser(string[] selectedPartys, string[] selectedRegions,
                                string[] selectedShelters, string[] selectedTrails, AppUser userToUpdate)
        {
            if (selectedPartys == null || selectedRegions == null ||
                selectedShelters == null || selectedTrails == null)
            {
                if (selectedPartys == null)
                {
                    userToUpdate.PermissionPartys = new List <PermissionParty>();
                }
                if (selectedRegions == null)
                {
                    userToUpdate.PermissionRegions = new List <PermissionRegion>();
                }
                if (selectedShelters == null)
                {
                    userToUpdate.PermissionShelters = new List <PermissionShelter>();
                }
                if (selectedTrails == null)
                {
                    userToUpdate.PermissionTrails = new List <PermissionTrail>();
                }

                return;
            }

            var selectedPartysHS = new HashSet <string>(selectedPartys);
            var userPartys       = new HashSet <int>
                                       (userToUpdate.PermissionPartys.Select(c => c.Party.IdParty));

            foreach (var party in _appDbContext.Partys)
            {
                if (selectedPartysHS.Contains(party.IdParty.ToString()))
                {
                    if (!userPartys.Contains(party.IdParty))
                    {
                        userToUpdate.PermissionPartys.Add(new PermissionParty {
                            IdUser = userToUpdate.Id, IdParty = party.IdParty
                        });
                    }
                }
                else
                {
                    if (userPartys.Contains(party.IdParty))
                    {
                        PermissionParty partyToRemove = userToUpdate.PermissionPartys.FirstOrDefault(i => i.IdParty == party.IdParty);
                        _appDbContext.Remove(partyToRemove);
                    }
                }
            }

            var selectedRegionsHS = new HashSet <string>(selectedRegions);
            var userRegions       = new HashSet <int>
                                        (userToUpdate.PermissionRegions.Select(c => c.Region.IdRegion));

            foreach (var region in _appDbContext.Regions)
            {
                if (selectedRegionsHS.Contains(region.IdRegion.ToString()))
                {
                    if (!userRegions.Contains(region.IdRegion))
                    {
                        userToUpdate.PermissionRegions.Add(new PermissionRegion {
                            IdUser = userToUpdate.Id, IdRegion = region.IdRegion
                        });
                    }
                }
                else
                {
                    if (userRegions.Contains(region.IdRegion))
                    {
                        PermissionRegion regionToRemove = userToUpdate.PermissionRegions.FirstOrDefault(i => i.IdRegion == region.IdRegion);
                        _appDbContext.Remove(regionToRemove);
                    }
                }
            }

            var selectedSheltersHS = new HashSet <string>(selectedShelters);
            var userShelters       = new HashSet <int>
                                         (userToUpdate.PermissionShelters.Select(c => c.Shelter.IdShelter));

            foreach (var shelter in _appDbContext.Shelters)
            {
                if (selectedSheltersHS.Contains(shelter.IdShelter.ToString()))
                {
                    if (!userShelters.Contains(shelter.IdShelter))
                    {
                        userToUpdate.PermissionShelters.Add(new PermissionShelter {
                            IdUser = userToUpdate.Id, IdShelter = shelter.IdShelter
                        });
                    }
                }
                else
                {
                    if (userShelters.Contains(shelter.IdShelter))
                    {
                        PermissionShelter shelterToRemove = userToUpdate.PermissionShelters.FirstOrDefault(i => i.IdShelter == shelter.IdShelter);
                        _appDbContext.Remove(shelterToRemove);
                    }
                }
            }

            var selectedTrailsHS = new HashSet <string>(selectedTrails);
            var userTrails       = new HashSet <int>
                                       (userToUpdate.PermissionTrails.Select(c => c.Trail.IdTrail));

            foreach (var trail in _appDbContext.Trails)
            {
                if (selectedTrailsHS.Contains(trail.IdTrail.ToString()))
                {
                    if (!userTrails.Contains(trail.IdTrail))
                    {
                        userToUpdate.PermissionTrails.Add(new PermissionTrail {
                            IdUser = userToUpdate.Id, IdTrail = trail.IdTrail
                        });
                    }
                }
                else
                {
                    if (userTrails.Contains(trail.IdTrail))
                    {
                        PermissionTrail trailToRemove = userToUpdate.PermissionTrails.FirstOrDefault(i => i.IdTrail == trail.IdTrail);
                        _appDbContext.Remove(trailToRemove);
                    }
                }
            }
        }
コード例 #9
0
        public async Task <IActionResult> Create(AppUser user, string[] selectedPartys, string[] selectedRegions, string[] selectedShelters, string[] selectedTrails)
        {
            if (selectedPartys != null)
            {
                user.PermissionPartys = new List <PermissionParty>();
                foreach (var party in selectedPartys)
                {
                    var partyToAdd = new PermissionParty {
                        IdUser = user.Id, IdParty = int.Parse(party)
                    };
                    user.PermissionPartys.Add(partyToAdd);
                }
            }

            if (selectedRegions != null)
            {
                user.PermissionRegions = new List <PermissionRegion>();
                foreach (var region in selectedRegions)
                {
                    var regionToAdd = new PermissionRegion {
                        IdUser = user.Id, IdRegion = int.Parse(region)
                    };
                    user.PermissionRegions.Add(regionToAdd);
                }
            }

            if (selectedShelters != null)
            {
                user.PermissionShelters = new List <PermissionShelter>();
                foreach (var shelter in selectedShelters)
                {
                    var shelterToAdd = new PermissionShelter {
                        IdUser = user.Id, IdShelter = int.Parse(shelter)
                    };
                    user.PermissionShelters.Add(shelterToAdd);
                }
            }

            if (selectedTrails != null)
            {
                user.PermissionTrails = new List <PermissionTrail>();
                foreach (var trail in selectedTrails)
                {
                    var trailToAdd = new PermissionTrail {
                        IdUser = user.Id, IdTrail = int.Parse(trail)
                    };
                    user.PermissionTrails.Add(trailToAdd);
                }
            }

            if (ModelState.IsValid)
            {
                _appDbContext.Add(user);
                await _appDbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            PopulateUser(user);

            return(View(user));
        }
コード例 #10
0
 public ViewResult Index([DataSourceRequest(Prefix = "Grid")] DataSourceRequest dsRequest, PermissionRegion searchPermissionRegion, int workerId)
 {
     //if(searchPermissionRegion!=null)
     //{
     //	if (dsRequest.Filters == null || (dsRequest.Filters != null && dsRequest.Filters.Count == 0))
     //	{
     //		if (dsRequest.Filters == null)
     //		{
     //			dsRequest.Filters = new List<IFilterDescriptor>();
     //		}
     //	}
     //}
     //DataSourceRequest dsRequestTotalCountQuery = new DataSourceRequest();
     //dsRequestTotalCountQuery.Filters = dsRequest.Filters;
     //DataSourceResult totalCountQuery = PermissionRegionRepository.All.ToDataSourceResult(dsRequestTotalCountQuery);
     //ViewData["total"] = totalCountQuery.Data.AsQueryable().Count();
     //if (dsRequest.PageSize == 0)
     //{
     //    dsRequest.PageSize = Constants.CommonConstants.DefaultPageSize;
     //}
     //DataSourceResult result = PermissionRegionRepository.AllIncluding(workerId,PermissionRegion => PermissionRegion.CreatedByWorker, PermissionRegion => PermissionRegion.LastUpdatedByWorker, PermissionRegion => PermissionRegion.Worker, PermissionRegion => PermissionRegion.WorkerRole).ToDataSourceResult(dsRequest);
     //return View(result.Data);
     return(View());
 }
コード例 #11
0
        public ActionResult SaveAjax(PermissionRegion PermissionRegion)
        {
            //id=0 means add operation, update operation otherwise
            bool isNew = PermissionRegion.ID == 0;

            //validate data
            if (ModelState.IsValid)
            {
                try
                {
                    PermissionRegion.SubProgramIDs = Request.Form["SubProgramIDs"].ToString(true).ToStringArray(',');
                    if (PermissionRegion.SubProgramIDs == null || (PermissionRegion.SubProgramIDs != null && PermissionRegion.SubProgramIDs.Length == 0))
                    {
                        throw new CustomException("Please select at least one sub-program");
                    }

                    //PermissionRegion.JamatkhanaIDs = Request.Form["JamatkhanaIDs"].ToString(true).ToStringArray(',');
                    //if (PermissionRegion.JamatkhanaIDs == null || (PermissionRegion.JamatkhanaIDs != null && PermissionRegion.JamatkhanaIDs.Length == 0))
                    //{
                    //    throw new CustomException("Please select at least one jamatkhana");
                    //}

                    //set the id of the permission who has added/updated this record
                    PermissionRegion.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
                    //call repository function to save the data in database
                    permissionregionRepository.InsertOrUpdate(PermissionRegion);
                    permissionregionRepository.Save();
                    //set status message
                    if (isNew)
                    {
                        PermissionRegion.SuccessMessage = "Region has been added successfully";
                    }
                    else
                    {
                        PermissionRegion.SuccessMessage = "Region has been updated successfully";
                    }
                }
                catch (DbUpdateException ex)
                {
                    PermissionRegion.ErrorMessage = "There is a problem adding data to database";
                }
                catch (CustomException ex)
                {
                    PermissionRegion.ErrorMessage = ex.UserDefinedMessage;
                }
                catch (Exception ex)
                {
                    ExceptionManager.Manage(ex);
                    PermissionRegion.ErrorMessage = Constants.Messages.UnhandelledError;
                }
            }
            else
            {
                foreach (var modelStateValue in ViewData.ModelState.Values)
                {
                    foreach (var error in modelStateValue.Errors)
                    {
                        PermissionRegion.ErrorMessage = error.ErrorMessage;
                        break;
                    }
                    if (PermissionRegion.ErrorMessage.IsNotNullOrEmpty())
                    {
                        break;
                    }
                }
            }
            //return the status message in json
            if (PermissionRegion.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, PermissionRegion) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, PermissionRegion) }));
            }
        }