public HttpResponseMessage Put(int id, Models.Donor donor)
        {
            if (ModelState.IsValid && id == donor.DonorID)
            {
                //contact.DateLastModified = DateTime.Now;
                //contact.LastModifiedBy = (new UserRepository().GetUser(User.Identity.Name)).UserID;
                var updated = _donorRepository.UpdateDonor(donor);
                if (updated)
                {
                    return(Request.CreateResponse
                               (HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotModified, "Could not modify Contact"));
                }
            }
            else
            {
                var errors     = ModelState.Select(x => x.Value.Errors).ToList();
                var errostring = new StringBuilder();
                foreach (var error in errors)
                {
                    var exMessage = error.Select(e => e.Exception.Message).ToList();
                    errostring.Append(exMessage);
                }

                return(Request.CreateErrorResponse(HttpStatusCode.NotModified, errostring.ToString()));
            }
        }
Beispiel #2
0
        public async Task <ActionResult <Donors> > PutDonor(int id, Donors donors)
        {
            try
            {
                if (id != donors.Id)
                {
                    return(BadRequest("Donor ID mismatch"));
                }

                var donorToUpdate = await donorRepository.GetDonor(id);

                if (donorToUpdate == null)
                {
                    return(NotFound($"Donor with Id = {id} not found"));
                }

                return(await donorRepository.UpdateDonor(donors));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error updating data"));
            }
        }