Esempio n. 1
0
        public async Task <ActionResult> CreateBloodDonor([FromBody] BloodDonorModel bloodDonor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var instance = BloodDonor.Create(bloodDonor.Type, bloodDonor.PatientId);

            try
            {
                var newBloodDonor = await _repository.AddAsync(instance);

                if (newBloodDonor == null)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false
                    }));
                }
                return(CreatedAtRoute("GetBloodDonorRoute", new { id = newBloodDonor.BloodDonorId },
                                      new ApiResponse {
                    Status = true, BloodDonor = newBloodDonor
                }));
            }
            catch
            {
                return(BadRequest(new ApiResponse {
                    Status = false
                }));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> UpdateBloodDonor(Guid id, [FromBody] BloodDonorModel bloodDonor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var instance = await _repository.GetByIdAsync(id);

            try
            {
                instance.Update(bloodDonor.Type, bloodDonor.PatientId);

                var status = await _repository.UpdateAsync(instance);

                if (!status)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false
                    }));
                }
                return(Ok(new ApiResponse {
                    Status = true, BloodDonor = instance
                }));
            }
            catch
            {
                return(BadRequest(new ApiResponse {
                    Status = false
                }));
            }
        }
Esempio n. 3
0
        public ActionResult BloodDonorRegistration(BloodDonorModel bloodDonor)
        {
            ViewBag.Donor = "active";

            List <BloodModel> bloodCategories;

            using (var ctx = new MedicalContext())
            {
                ctx.BloodDonor.Add(bloodDonor);
                ctx.SaveChanges();
                bloodCategories = ctx.Blood.ToList();
            }
            ViewBag.Category = bloodCategories;
            return(View());
        }
Esempio n. 4
0
        public JsonResult GetAllDonorInfoById(int id)
        {
            List <BloodDonorModel> donor = new List <BloodDonorModel>();

            using (var ctx = new MedicalContext())
            {
                var a = ctx.BloodDonor.Where(s => s.Bloodid == id);
                foreach (var k in a)
                {
                    BloodDonorModel doc = new BloodDonorModel();
                    doc.DonorName = k.DonorName;
                    doc.Number    = k.Number;
                    doc.Address   = k.Address;

                    donor.Add(doc);
                }
            }
            return(Json(donor));
        }
        public async Task <ActionResult> UpdateBloodDonor(Guid id, [FromBody] BloodDonorModel bloodDonor, [FromHeader(Name = "Authorization")] string value)
        {
            var token    = new JwtSecurityTokenHandler().ReadJwtToken(value);
            var issuer   = token.Claims.First(claim => claim.Type == "iss").Value;
            var audience = token.Claims.First(claim => claim.Type == "aud").Value;

            if (issuer != "MyIssuer" || audience != "MyAudience")
            {
                return(Unauthorized());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var instance = await _repository.GetByIdAsync(id);

            try
            {
                instance.Update(bloodDonor.Type, bloodDonor.PatientId, bloodDonor.ApplyDate, bloodDonor.HaveDonated, bloodDonor.PatientConfirmed, bloodDonor.PendingPatientId);

                var status = await _repository.UpdateAsync(instance);

                if (!status)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false
                    }));
                }
                return(Ok(new ApiResponse {
                    Status = true, BloodDonor = instance
                }));
            }
            catch
            {
                return(BadRequest(new ApiResponse {
                    Status = false
                }));
            }
        }
        public async Task <ActionResult> CreateBloodDonor([FromBody] BloodDonorModel bloodDonor, [FromHeader(Name = "Authorization")] string value)
        {
            var token    = new JwtSecurityTokenHandler().ReadJwtToken(value);
            var issuer   = token.Claims.First(claim => claim.Type == "iss").Value;
            var audience = token.Claims.First(claim => claim.Type == "aud").Value;

            if (issuer != "MyIssuer" || audience != "MyAudience")
            {
                return(Unauthorized());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var instance = BloodDonor.Create(bloodDonor.Type, bloodDonor.PatientId, bloodDonor.ApplyDate);

            try
            {
                var newBloodDonor = await _repository.AddAsync(instance);

                if (newBloodDonor == null)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false
                    }));
                }
                return(CreatedAtRoute("GetBloodDonorRoute", new { id = newBloodDonor.BloodDonorId },
                                      new ApiResponse {
                    Status = true, BloodDonor = newBloodDonor
                }));
            }
            catch
            {
                return(BadRequest(new ApiResponse {
                    Status = false
                }));
            }
        }