public IActionResult Get(string text = null)
        {
            var orgs = _orgRepository.GetAll();

            if (text != null)
            {
                var filteredList = orgs.Where(org => org.Name.ToLower().Contains(text.ToLower())).ToList();
                return(Ok(filteredList));
            }

            return(Ok(orgs));
        }
        //[BasicAuthentication]
        // GET api/<controller>
        public IHttpActionResult Get()
        {
            var organisations = orgRep.GetAll();
            var filePath      = HttpContext.Current.Server.MapPath("~/Media/Files");

            foreach (Organisation organisation in organisations)
            {
                linkGen(organisation);
                organisation.ApprovalPath = filePath + "/" + organisation.ApprovalPath;
            }

            return(Ok(organisations));
        }
        public async Task <IActionResult> Post([FromBody] PendingOrganisation organisation, [FromServices] IOptions <ApiBehaviorOptions> apiBehaviorOptions)
        {
            var currentOrgs = _orgRepository.GetAll();
            var pendingOrgs = _pendingOrgRepository.GetAll();

            try
            {
                Guid.Parse(organisation.Id);
            }
            catch (Exception _)
            {
                ModelState.AddModelError(nameof(Organisation.Id), "Organization Id is not a valid Guid");
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }
            if (organisation.CharityNumber > 0 &&
                (currentOrgs.Any(org => org.CharityNumber == organisation.CharityNumber) ||
                 pendingOrgs.Any(org => org.CharityNumber == organisation.CharityNumber)))
            {
                ModelState.AddModelError(nameof(Organisation.CharityNumber), "Charity number already exists.");
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }
            if (currentOrgs.Any(org => org.Name == organisation.Name) || pendingOrgs.Any(org => org.Name == organisation.Name))
            {
                ModelState.AddModelError(nameof(Organisation.Name), "Organisation name already exists.");
                return(apiBehaviorOptions.Value.InvalidModelStateResponseFactory(ControllerContext));
            }
            else
            {
                organisation.UserId    = JWTAttributesService.GetSubject(Request);
                organisation.UserEmail = JWTAttributesService.GetEmail(Request);
                await _pendingOrgRepository.InsertOne(organisation);

                await _sendgridSender.SendOrgRequestEmail(
                    new SendGrid.Helpers.Mail.EmailAddress("*****@*****.**"),
                    new SendGrid.Helpers.Mail.EmailAddress(_configuration["Admin:EmailAddress"]),
                    organisation.Name
                    );

                return(Accepted(organisation));
            }
        }
 public async Task <IEnumerable <Organisation> > GetAll()
 {
     return(await _orgRepository.GetAll());
 }
示例#5
0
 public IEnumerable <Organisation> GetAll()
 {
     //return new List<Organisation>();
     return(_or.GetAll());
 }