public bool EditOrg(OrganisationsViewModel model) { var success = false; if (model != null) { using (var scope = new TransactionScope()) { var organisationModel = unitOfWork.OrganisationRepository.GetByID(model.OrgId); if (organisationModel != null) { organisationModel.OrgId = model.OrgId; organisationModel.OrgName = model.OrgName; organisationModel.FirstName = model.FirstName; organisationModel.ShortName = model.ShortName; organisationModel.Email = model.Email; organisationModel.Phone = model.Phone; unitOfWork.OrganisationRepository.Update(organisationModel); unitOfWork.Save(); scope.Complete(); success = true; } } } return(success); }
public async Task <IActionResult> LinkOrganisations() { ApplicationDbContext adc = new ApplicationDbContext(); //Get the ID of the current user var user = await GetCurrentUserAsync(); var uID = user.Id; //Get a list of all linked orgs for that user ID IQueryable <ApplicationOrganisations> AOL = from q in adc.UserOrganisationLinks where q.ApplicationUserId == uID select q.ApplicationOrganisation; List <ApplicationOrganisations> linked = AOL.ToList(); //Convert to list //Fill a list with all the IDs of the currently linked orgs List <long> linkedIDs = new List <long>(linked.Count); foreach (ApplicationOrganisations ao in linked) { linkedIDs.Add(ao.Id); } //Get a list of currently available orgs for linking - by excluding those with IDs listed in linkedIds IQueryable <ApplicationOrganisations> AOUL = from q in adc.ApplicationOrganisations where !linkedIDs.Contains(q.Id) select q; List <ApplicationOrganisations> unlinked = AOUL.ToList(); //Create a new view model and assign the linked and unlinked orgs OrganisationsViewModel OVM = new OrganisationsViewModel(); //OVM.LinkedOrgs = linked; List <SelectListItem> SLI = new List <SelectListItem>(); foreach (ApplicationOrganisations ao in linked) { SLI.Add(new SelectListItem { Text = ao.organisationName, Value = ao.Id.ToString() }); } OVM.LinkedOrgs = SLI; OVM.UnlinkedOrgs = unlinked; //Pass the linked/unlinked orgs to the view return(View(OVM)); }
public async Task <IActionResult> Organisations() { var currentRoleUserEmail = HttpContext.User.GetNormalisedEmail(); var organisationIds = HttpContext.User.GetOrganisationIds(); var organisations = await _identityManagementRepository.GetOrganisationsByEmailAndRoleAsync(currentRoleUserEmail, RoleType.Administrator, organisationIds); var model = new OrganisationsViewModel { Organisations = organisations }; return(View(model)); }
public IHttpActionResult AddOrg(OrganisationsViewModel model) { ResponseViewModel ResponseObj = new ResponseViewModel(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { bool userAdded = _tenantDataManager.AddOrg(model); return(Ok("ok")); } catch (Exception EX) { throw EX; } return(BadRequest(ModelState)); }
public IActionResult Index() { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); IEnumerable <OrganisationDto> organisations; OrganisationsViewModel organisationsViewModel = new OrganisationsViewModel();; try { organisations = _service.GetOrganisations(userId); organisationsViewModel = new OrganisationsViewModel(); organisationsViewModel.Organisations = organisations; } catch (Exception ex) { ViewData["ErrorMessage"] = ex.Message; ViewData["Prompt"] = "Please contact your manager...."; return(View("ErrorPage")); } return(View(organisationsViewModel)); }
public IHttpActionResult EditOrg(OrganisationsViewModel model) { ResponseViewModel ResponseObj = new ResponseViewModel(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { // if (result.Succeeded == true) // bool userAdded = _tenantDataManager.EditOrg(model); return(Ok("Ok")); } catch (Exception EX) { throw EX; } return(BadRequest(ModelState)); }
public bool AddOrg(OrganisationsViewModel model) { vCIOPRoEntities context = new vCIOPRoEntities(); bool flag = false; using (var dbContextTransaction = context.Database.BeginTransaction()) { try { Guid UniqueTenantId = System.Guid.NewGuid(); Organisation TntDtl = new Organisation() { OrgName = model.OrgName, ShortName = model.ShortName, FirstName = model.FirstName, LastName = model.LastName, Description = model.Description, Email = model.Email, Phone = model.Phone, ImagePath = "fghuir", AlertMessage = "fjg" }; unitOfWork.GetRepositoryInstance <Organisation>().Insert(TntDtl); unitOfWork.Save(); dbContextTransaction.Commit(); flag = true; } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } return(true); }
public async Task <IActionResult> IndexAsync(IFormFile formFile, [FromServices] IHostingEnvironment hostingEnviroment) { string filePath = $"{hostingEnviroment.WebRootPath}\\files\\"; string fileTitle = filePath + formFile.FileName; using (FileStream fileStream = System.IO.File.Create(fileTitle)) { formFile.CopyTo(fileStream); fileStream.Flush(); } FileService fileService = new FileService(); List <Organisation> organisations = await fileService.ReadFileAsync(fileTitle); RequestService requestService = new RequestService(); List <Organisation> updatedOrganisations = await requestService.GetOrganizations(organisations, filePath); OrganisationsViewModel model = new OrganisationsViewModel() { Organisations = updatedOrganisations }; return(View(model)); }
public ActionResult Index([DefaultValue(1)] int page, string keywords, [DefaultValue(12)] int pgsize) { try { //var organisation = db.Organisation.Include("OrganisationType"); //return View(organisation.ToList()); List <sw.Organisation> rowsToShow = new List <sw.Organisation>(); int totalRecords = 0; int orgID = getOrgID(); if (orgID == 0) { if (!string.IsNullOrEmpty(keywords)) { rowsToShow = swdb.Organisation.Where(x => x.StatusID != 2 && x.Name.ToUpper().Contains(keywords.Trim().ToUpper())).OrderBy(x => x.Id).Include("OrganisationType").Skip((page - 1) * pgsize).Take(pgsize).ToList(); totalRecords = swdb.Organisation.Count(x => x.StatusID != 2 && x.Name.ToUpper().Contains(keywords.Trim().ToUpper())); } else { rowsToShow = swdb.Organisation.Where(x => x.StatusID != 2).OrderBy(x => x.Id).Include("OrganisationType").Skip((page - 1) * pgsize).Take(pgsize).ToList(); totalRecords = swdb.Organisation.Count(x => x.StatusID != 2); } } else { if (!string.IsNullOrEmpty(keywords)) { rowsToShow = swdb.Organisation.Where(x => x.Id == orgID && x.Name.ToUpper().Contains(keywords.Trim().ToUpper())).OrderBy(x => x.Id).Include("OrganisationType").Skip((page - 1) * pgsize).Take(pgsize).ToList(); totalRecords = swdb.Organisation.Count(x => x.Id == orgID && x.Name.ToUpper().Contains(keywords.Trim().ToUpper())); } else { rowsToShow = swdb.Organisation.Where(x => x.Id == orgID).OrderBy(x => x.Id).Include("OrganisationType").Skip((page - 1) * pgsize).Take(pgsize).ToList(); totalRecords = swdb.Organisation.Count(x => x.Id == orgID); } } OrganisationsViewModel model = new OrganisationsViewModel() { Rows = rowsToShow, orgID = orgID, PagingInfo = new PagingInfo { FirstItem = ((page - 1) * pgsize) + 1, LastItem = page * pgsize, CurrentPage = page, ItemsPerPage = pgsize, TotalItems = totalRecords }, CurrentKeywords = keywords, PageSize = pgsize }; return(View(model)); } catch (Exception ex) { // Log with Elmah TempData["message"] = Settings.Default.GenericExceptionMessage; return(RedirectToAction("Index", "Home", new { area = "Admin" })); } }
public IActionResult Index(OrganisationsViewModel model = null) { model = model == null ? new OrganisationsViewModel() : model; return(View(model)); }
public RegisterPage(IOrganisationRepository organisationRepository) { InitializeComponent(); OrganisationRepository = organisationRepository; BindingContext = new OrganisationsViewModel(organisationRepository); }
public async Task <IActionResult> SetLinks(OrganisationsViewModel ovm) { ApplicationDbContext adc = new ApplicationDbContext(); //Get the ID of the current user var user = await GetCurrentUserAsync(); var uID = user.Id; //Get a list of all linked orgs for that user ID IQueryable <ApplicationOrganisations> AOL = from q in adc.UserOrganisationLinks where q.ApplicationUserId == uID select q.ApplicationOrganisation; List <ApplicationOrganisations> linked = AOL.ToList(); //Convert to list IQueryable <UserOrganisationLinks> UOL = from q in adc.UserOrganisationLinks where q.ApplicationUserId == uID select q; List <UserOrganisationLinks> UOLlinked = UOL.ToList(); //Convert to list //Check if the user actually passed any new orgs links through. Either the user deleted all their links or had none when they saved if (ovm.ReturnedIDs != null && ovm.ReturnedIDs.Count != 0) { //Fill a list with all the IDs of the currently linked orgs List <long> linkedIDs = new List <long>(linked.Count); foreach (ApplicationOrganisations ao in linked) { linkedIDs.Add(ao.Id); } /*IEnumerable<long> removedFromDB = from q in ovm.ReturnedIDs * where linkedIDs.Contains(q) * select q; */ IEnumerable <long> removedFromDB = from q in linkedIDs where !ovm.ReturnedIDs.Contains(q) select q; List <long> removedFromDBList = removedFromDB.ToList(); IEnumerable <UserOrganisationLinks> orgsToRemove = from org in adc.UserOrganisationLinks where removedFromDBList.Contains(org.ApplicationOrganisationsId) select org; List <UserOrganisationLinks> orgsToRemoveList = orgsToRemove.ToList(); foreach (UserOrganisationLinks orgLink in orgsToRemoveList) { adc.UserOrganisationLinks.Remove(orgLink); } //Create a collection of IDs from the newly added Orgs, by excluding those that were already there IEnumerable <long> removedDoubles = from q in ovm.ReturnedIDs where !linkedIDs.Contains(q) select q; //For each of this new IDs create a new link to the currently logged in User. foreach (long id in removedDoubles) { UserOrganisationLinks uol = new UserOrganisationLinks(); uol.ApplicationUserId = uID; uol.ApplicationOrganisationsId = (int)id; adc.UserOrganisationLinks.Add(uol); } //Commit the DB adc.SaveChanges(); } else //Else no IDs were passed over. So either the DB was already empty or the user has deleted all their org links { //Check if the user has any orgLinks if (linked.Count != 0) { //Since they had links previously they must have removed all their links //for the returnedID count to be zero or the list to be Null //so remove them all from the DB foreach (UserOrganisationLinks uol in UOL) { adc.UserOrganisationLinks.Remove(uol); } //Commit the DB adc.SaveChanges(); } //Otherwise they never had any links and they pressed 'save' so do nothing. } return(RedirectToAction("LinkOrganisations")); }