Exemplo n.º 1
0
 // PUT api/Complainant/5
 public IHttpActionResult Put(int id, [FromBody] Complainant complainant)
 {
     complainantService = new ComplainantService();
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     complainantService.Update(id, complainant);
     return(StatusCode(HttpStatusCode.OK));
 }
Exemplo n.º 2
0
        // GET api/Complainant/5
        public IHttpActionResult Get(int id)
        {
            complainantService = new ComplainantService();
            var Complainant = complainantService.GetById(id);

            if (Complainant != null)
            {
                return(Ok(Complainant));
            }

            return(Content(HttpStatusCode.NotFound, APIMessageHelper.EntityNotFoundMessage("Complainant", id)));
        }
Exemplo n.º 3
0
        // DELETE api/Complainant/5
        public IHttpActionResult Delete(int id)
        {
            complainantService = new ComplainantService();
            var response = complainantService.Delete(id);

            if (response.Success)
            {
                return(Ok(id));
            }

            return(Content(HttpStatusCode.BadRequest, response.Message));
        }
Exemplo n.º 4
0
        public IHttpActionResult Get()
        {
            complainantService = new ComplainantService();
            var complainants = complainantService.GetAll();

            if (complainants != null)
            {
                var complainantEntities = complainants as List <Complainant> ?? complainants.ToList();
                if (complainantEntities.Any())
                {
                    return(Ok(complainantEntities));
                }
            }
            return(Content(HttpStatusCode.NotFound, APIMessageHelper.ListNotFoundMessage("Complainants")));
        }
Exemplo n.º 5
0
        // POST api/Complainant
        public IHttpActionResult Post([FromBody] Complainant complainant)
        {
            complainantService = new ComplainantService();
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = complainantService.Add(complainant);

            if (response.Success)
            {
                return(Ok(response.ReturnedId));
            }
            return(Content(HttpStatusCode.BadRequest, response.Message));
        }
Exemplo n.º 6
0
        public IHttpActionResult GetShortList()
        {
            complainantService = new ComplainantService();
            var complainants = complainantService.GetAll();
            List <ComplainantList> complainantList = new List <ComplainantList>();

            foreach (var complainant in complainants)
            {
                complainantList.Add(new ComplainantList()
                {
                    Id       = complainant.Id,
                    NIC      = complainant.NIC,
                    FullName = complainant.NIC + "-" + complainant.FullName
                });
            }
            if (complainantList.Count > 0)
            {
                return(Ok(complainantList));
            }
            else
            {
                return(Content(HttpStatusCode.NotFound, APIMessageHelper.ListNotFoundMessage("Complainants")));
            }
        }