Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateDonor(string Id, DonorDto donor)
        {
            // check if model state is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (donor.ImageArray != null)
            {
                //upload camera image to contents folder
                var stream   = new MemoryStream(donor.ImageArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = $"{guid}.jpg";
                var folder   = "~/Contents/Donors";
                var fullPath = $"{folder}/{file}";
                var response = FilesHelper.UploadPhoto(stream, file);
                if (response)
                {
                    donor.ImagePath = fullPath;
                }
                // save donor info to database
                DateTime now  = DateTime.Now;
                var      user = await _db.Donors.SingleOrDefaultAsync(d => d.Id == Id);

                user.FirstName      = donor.FirstName;
                user.LastName       = donor.LastName;
                user.Phone          = donor.Phone;
                user.Gender         = donor.Gender;
                user.RegionId       = donor.RegionId;
                user.Location       = donor.Location;
                user.Longitude      = donor.Longitude;
                user.Latitude       = donor.Latitude;
                user.ImagePath      = donor.ImagePath;
                user.CreatedDate    = now;
                user.LastUpdateDate = now;
            }
            else
            {
                DateTime now  = DateTime.Now;
                var      user = await _db.Donors.SingleOrDefaultAsync(d => d.Id == Id);

                user.FirstName      = donor.FirstName;
                user.LastName       = donor.LastName;
                user.Phone          = donor.Phone;
                user.Gender         = donor.Gender;
                user.RegionId       = donor.RegionId;
                user.Location       = donor.Location;
                user.Longitude      = donor.Longitude;
                user.Latitude       = donor.Latitude;
                user.CreatedDate    = now;
                user.LastUpdateDate = now;
            }

            // _db.Donors.Add(user);
            if (await _db.SaveChangesAsync() > 0)
            {
                return(Ok());                                       //action successful
            }
            return(BadRequest("Could not save donor information")); //failed
        }
        // GET: Donation/Details/5
        public ActionResult Details(int id)
        {
            ShowDonation        ViewModel = new ShowDonation();
            string              url       = "donationdata/finddonation/" + id;
            HttpResponseMessage response  = client.GetAsync(url).Result;

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into donation data transfer object
                DonationDto SelectedDonation = response.Content.ReadAsAsync <DonationDto>().Result;
                ViewModel.donation = SelectedDonation;


                url      = "donationdata/finddonorfordonation/" + id;
                response = client.GetAsync(url).Result;
                DonorDto SelectedDonor = response.Content.ReadAsAsync <DonorDto>().Result;
                ViewModel.donor = SelectedDonor;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult FindDonor(int id)
        {
            //find donor data
            Donor Donor = db.Donors.Find(id);

            if (Donor == null)
            {
                return(NotFound());
            }

            //Put into Dto form
            DonorDto DonorDto = new DonorDto
            {
                DonorId    = Donor.DonorId,
                Email      = Donor.Email,
                Type       = Donor.Type,
                OrgName    = Donor.OrgName,
                Fname      = Donor.Fname,
                Lname      = Donor.Lname,
                Addressl1  = Donor.Addressl1,
                Addressl2  = Donor.Addressl2,
                City       = Donor.City,
                Country    = Donor.Country,
                Province   = Donor.Province,
                PostalCode = Donor.PostalCode
            };

            return(Ok(DonorDto));
        }
Ejemplo n.º 4
0
        public IHttpActionResult GetDonors()
        {
            IEnumerable <Donor> Donors    = db.Donors.ToList();
            List <DonorDto>     DonorDtos = new List <DonorDto> {
            };

            //Here you can choose which information is exposed to the API
            foreach (var Donor in Donors)
            {
                DonorDto NewDonor = new DonorDto
                {
                    DonorId    = Donor.DonorId,
                    Email      = Donor.Email,
                    Type       = Donor.Type,
                    OrgName    = Donor.OrgName,
                    Fname      = Donor.Fname,
                    Lname      = Donor.Lname,
                    Addressl1  = Donor.Addressl1,
                    Addressl2  = Donor.Addressl2,
                    City       = Donor.City,
                    Country    = Donor.Country,
                    Province   = Donor.Province,
                    PostalCode = Donor.PostalCode
                };
                DonorDtos.Add(NewDonor);
            }
            return(Ok(DonorDtos));
        }
Ejemplo n.º 5
0
        public IHttpActionResult FindDonorForDonation(int id)
        {
            //Finds the first team which has any players
            //that match the input playerid
            Donor Donor = db.Donors
                          .Where(dn => dn.Donations.Any(dnt => dnt.DonationId == id))
                          .FirstOrDefault();

            //if not found, return 404 status code.
            if (Donor == null)
            {
                return(NotFound());
            }

            //put into a 'friendly object format'
            DonorDto DonorDto = new DonorDto
            {
                DonorId    = Donor.DonorId,
                Email      = Donor.Email,
                Type       = Donor.Type,
                OrgName    = Donor.OrgName,
                Fname      = Donor.Fname,
                Lname      = Donor.Lname,
                Addressl1  = Donor.Addressl1,
                Addressl2  = Donor.Addressl2,
                City       = Donor.City,
                Country    = Donor.Country,
                Province   = Donor.Province,
                PostalCode = Donor.PostalCode
            };

            //pass along data as 200 status code OK response
            return(Ok(DonorDto));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create(DonorDto donorDto)
        {
            if (donorDto == null)
            {
                throw new ArgumentNullException(nameof(donorDto));
            }
            if (ModelState.IsValid)
            {
                donorService.AddDonor(mapper.Map <Models.Donor>(donorDto));
                await donorService.SaveChangesAsync();

                return(RedirectToAction("DonorComplete"));
            }
            return(View(donorDto));
        }
Ejemplo n.º 7
0
        public IHttpActionResult CreateDonor(DonorDto donorDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var donor = Mapper.Map <DonorDto, Donor>(donorDto);

            _context.Donors.Add(donor);
            _context.SaveChanges();

            donorDto.Id = donor.Id;

            //we return the uri of the new donor
            return(Created(new Uri(Request.RequestUri + "/" + donor.Id), donorDto));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> AddDonor(DonorDto donorUser)
        {
            // check if model state is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //upload camera image to contents folder
            var stream   = new MemoryStream(donorUser.ImageArray);
            var guid     = Guid.NewGuid().ToString();
            var file     = $"{guid}.jpg";
            var folder   = "~/Contents/Donors";
            var fullPath = $"{folder}/{file}";
            var response = FilesHelper.UploadPhoto(stream, file);

            if (response)
            {
                donorUser.ImagePath = fullPath;
            }
            // save donor info to database
            DateTime now  = DateTime.Now;
            var      user = new Donor
            {
                Id             = donorUser.Id,
                FirstName      = donorUser.FirstName,
                LastName       = donorUser.LastName,
                Email          = donorUser.Email,
                Phone          = donorUser.Phone,
                Gender         = donorUser.Gender,
                RegionId       = donorUser.RegionId,
                Location       = donorUser.Location,
                Longitude      = donorUser.Longitude,
                Latitude       = donorUser.Latitude,
                ImagePath      = donorUser.ImagePath,
                CreatedDate    = now,
                LastUpdateDate = now
            };

            _db.Donors.Add(user);
            if (await _db.SaveChangesAsync() > 0)
            {
                return(Ok());                                       //action successful
            }
            return(BadRequest("Could not save donor information")); //failed
        }
        public ActionResult DeleteConfirm(int id)
        {
            string url = "donordata/finddonor/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into Team data transfer object
                DonorDto SelectedDonor = response.Content.ReadAsAsync <DonorDto>().Result;
                return(View(SelectedDonor));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
Ejemplo n.º 10
0
        public IHttpActionResult UpdateDonor(int id, DonorDto donorDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var donorInDb = _context.Donors.SingleOrDefault(d => d.Id == id);

            if (donorInDb == null)
            {
                return(NotFound());
            }


            Mapper.Map(donorDto, donorInDb);

            _context.SaveChanges();

            return(Ok(Mapper.Map(donorDto, donorInDb)));
        }