Esempio n. 1
0
        public ActionResult <Donar> PostDonar([FromBody] Donar donar)
        {
            try
            {
                _log4net.Info("Http Ppost Request Initiated");
                if (ModelState.IsValid)
                {
                    _log4net.Info("Obtained Valid Model");

                    var donaradded = _repository.Add(donar);

                    if (donaradded > 0)
                    {
                        return(CreatedAtAction("GetDonar", new { id = donar.DonorId }, donar));
                    }
                    else
                    {
                        return(BadRequest("Donate for valid Organization"));
                    }
                }
            }
            catch (Exception e)
            {
                _log4net.Error("Http post Request Failed Due to " + e.Message);


                return(NotFound());
            }
            return(BadRequest());
        }
Esempio n. 2
0
        public async Task <ActionResult <Donar> > PostDonar(Donar donar)
        {
            _context.Donar.Add(donar);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDonar", new { id = donar.DonorId }, donar));
        }
Esempio n. 3
0
        public async Task <IActionResult> PutDonar(int id, Donar donar)
        {
            if (id != donar.DonorId)
            {
                return(BadRequest());
            }

            _context.Entry(donar).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DonarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult> Create(int id, Donar donar)
        {
            if (HttpContext.Session.GetString("token") == null)
            {
                _log4net.Error("Session Expired while creating donar");

                return(RedirectToAction("Login", "Login"));
            }
            _log4net.Info("http post  request initiated by donar " + donar.DonorName);

            //Code for Donation
            donar.organization_Id = id;
            using (var httpclinet = new HttpClient())
            {
                //395
                StringContent content = new StringContent(JsonConvert.SerializeObject(donar), Encoding.UTF8, "application/json");
                using (var response = await httpclinet.PostAsync("https://851321donarservice.azurewebsites.net/api/donars", content))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    // donar = JsonConvert.DeserializeObject<Donar>(apiResponse);
                }
            }

            //Updating Total Funds Donated To Organization

            Organization org = new Organization();

            using (var client = new HttpClient())
            {
                var contentType = new MediaTypeWithQualityHeaderValue("application/json");
                client.DefaultRequestHeaders.Accept.Add(contentType);
                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token"));
                //356 https ://localhost:44353/api/organization/
                using (var response = await client.GetAsync("https://851321orgservice.azurewebsites.net/api/organization/" + id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    org = JsonConvert.DeserializeObject <Organization>(apiResponse);
                }
                double donations = Convert.ToInt32(org.TotalDonations);
                org.TotalDonations = (donar.Amount + donations).ToString();
                StringContent content = new StringContent(JsonConvert.SerializeObject(org), Encoding.UTF8, "application/json");
                //https ://localhost:44353/api/organization
                using (var response = await client.PutAsync("https://851321orgservice.azurewebsites.net/api/organization", content))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();
                }
            }



            return(RedirectToAction("Index", "Organization"));
        }
 public ActionResult Edit()
 {
     if (Session["UserId"] != null)
     {
         string username = (string)Session["UserId"];
         Donar  donar    = db.Donars.FirstOrDefault(n => n.Username == username);
         return(View(donar));
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
 public ActionResult Register(Donar donar)
 {
     if (ModelState.IsValid)
     {
         LoginDetail login = new LoginDetail();
         login.Username = donar.Username;
         login.Password = donar.Password;
         login.LoginAs  = "Donar";
         db.LoginDetails.Add(login);
         db.Donars.Add(donar);
         db.SaveChanges();
         return(RedirectToAction("Login", "Login"));
     }
     return(View());
 }
        public ActionResult Register()
        {
            Donar dr        = new Donar();
            Donar lastDonar = db.Donars.OrderByDescending(n => n.DId).FirstOrDefault();

            if (lastDonar == null)
            {
                dr.DId = "DR1";
            }
            else
            {
                dr.DId = "DR" + (Convert.ToInt32(lastDonar.DId.Substring(2, lastDonar.DId.Length - 2)) + 1).ToString();
            }
            return(View(dr));
        }
        public void mail(string Username, string trid)
        {
            Donation dn      = db.Donations.Find(trid);
            Donar    donar   = db.Donars.FirstOrDefault(d => d.DId == dn.DId);
            NGO      ngo     = db.NGOes.FirstOrDefault(n => n.NId == dn.NgId);
            string   subject = "Donation Receipt";
            string   body    = "Hello " + donar.DName.ToUpperInvariant() + ",\nThank you for making donation for NGO.Here is the receipt of Donation you have made for your future references.\n\nAmount          : Rs" + dn.Amount + "\n\n" +
                               "Donar ID        : " + donar.DId + "\n\n" +
                               "NGO ID          : " + ngo.NId + "\n\n" +
                               "NGO Name        : " + ngo.NgName + "\n\n" +
                               "Transaction Id  : " + trid + "\n\n" +
                               "Transaction Date: " + dn.TransactionDate + "\n\n\n\n" +
                               "Thank You";

            SendEmail(Username, subject, body);
        }
Esempio n. 9
0
        public ActionResult Login(LoginDetail loginDetails)
        {
            if (ModelState.IsValid)
            {
                LoginDetail user = new LoginDetail();
                user = db.LoginDetails.FirstOrDefault(u => u.Username == loginDetails.Username);
                if (user != null)
                {
                    if (user.Username == loginDetails.Username && user.Password == loginDetails.Password)
                    {
                        Session["UserId"] = user.Username;

                        if (user.LoginAs.Equals("Donar"))
                        {
                            Donar donar = db.Donars.FirstOrDefault(d => d.Username == user.Username);
                            TempData["Dname"] = donar.DName;
                            return(RedirectToAction("Index", "Donar"));
                        }
                        if (user.LoginAs.Equals("NGO"))
                        {
                            NGO ngo = db.NGOes.FirstOrDefault(n => n.Username == user.Username);
                            TempData["Ngname"] = ngo.NgName;
                            return(RedirectToAction("start", "NGO"));
                        }
                        if (user.LoginAs.Equals("Admin"))
                        {
                            return(RedirectToAction("Index", "Admin"));
                        }
                    }
                    else
                    {
                        ViewBag.Message = "Invalid Password";
                    }
                    return(View());
                }
                else
                {
                    ViewBag.Message = "User does not exist";
                    return(View());
                }
            }
            return(View());
        }
 public ActionResult Edit([Bind(Include = "DId,DName,Phone,Address,Username,Password,ConfirmPassword")] Donar donar)
 {
     if (ModelState.IsValid)
     {
         LoginDetail login = db.LoginDetails.Find(donar.Username);
         if (login.Password == donar.Password)
         {
             db.Entry(donar).State = EntityState.Modified;
             db.Entry(donar).Property("Password").IsModified = false;
             db.SaveChanges();
             TempData["Dname"] = donar.DName;
             return(View());
         }
         else
         {
             ViewBag.Message = "Invalid Password";
         }
     }
     return(View(donar));
 }
 public ActionResult Donate()
 {
     if (Session["UserId"] != null)
     {
         Donation donation     = new Donation();
         Donation lastDonation = db.Donations.OrderByDescending(n => n.TransactionID).FirstOrDefault();
         string   username     = (string)Session["UserId"];
         Donar    donar        = db.Donars.FirstOrDefault(d => d.Username == username);
         donation.DId = donar.DId;
         if (lastDonation == null)
         {
             donation.TransactionID = "TR1";
         }
         else
         {
             donation.TransactionID = "TR" + (Convert.ToInt32(lastDonation.TransactionID.Substring(2, lastDonation.TransactionID.Length - 2)) + 1).ToString();
         }
         List <SelectListItem> ngo = new List <SelectListItem>();
         List <NGO>            ng  = db.NGOes.ToList();
         List <NGO>            n1  = new List <NGO>();
         foreach (NGO ngo1 in ng)
         {
             Verification verify = db.Verifications.Find(ngo1.NId);
             if (verify != null)
             {
                 if (verify.status.Equals("Verified"))
                 {
                     n1.Add(ngo1);
                 }
             }
         }
         ViewBag.NGO = new SelectList(n1, "NId", "NId");
         return(View(donation));
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
Esempio n. 12
0
        public ActionResult <Donar> PostDonar([FromBody] Donar donar)
        {
            try
            {
                _log4net.Info("Http post Request Initiated for the donar Id " + donar.DonorId);
                if (ModelState.IsValid)
                {
                    _log4net.Info("Obtained Valid Model");

                    _repository.Add(donar);


                    return(CreatedAtAction("GetDonar", new { id = donar.DonorId }, donar));
                }
            }
            catch (Exception e)
            {
                _log4net.Error("Http post Request Failed Due to " + e.Message);


                return(NotFound());
            }
            return(BadRequest());
        }