示例#1
0
        public Donation Create(Campaign campaign, Fundraiser fundraiser, DonationStatus status, double amount, string currencyCode,
                               double amountInDefaultCurrency, string donorUserId, string donorDisplayName = null, string referenceNumber = null)
        {
            if (fundraiser != null && fundraiser.CampaignId != campaign.Id) // validate campaign
            {
                throw new InvalidOperationException("fundraiser campaign id does not match");
            }

            var donation = new Donation
            {
                Campaign                = campaign,
                Fundraiser              = fundraiser,
                Status                  = status,
                Amount                  = amount,
                CurrencyCode            = currencyCode,
                AmountInDefaultCurrency = amountInDefaultCurrency,
                DonorUserId             = donorUserId,
                DonorDisplayName        = donorDisplayName,
                ReferenceNumber         = referenceNumber,
                DateCreated             = DateTime.Now,
                DateLastUpdated         = DateTime.Now
            };

            if (currencyCode == campaign.DefaultCurrencyCode && amount != amountInDefaultCurrency)
            {
                throw new InvalidOperationException("invalid amount (does not match amount in default currency)");
            }

            _context.Donations.Add(donation);
            _context.SaveChanges();
            return(donation);
        }
        internal Fundraiser Edit(Fundraiser newFundraiser)
        {
            Fundraiser currentFundraiser = GetById(newFundraiser.Id);

            if (newFundraiser.Goal == null)
            {
                newFundraiser.Goal = currentFundraiser.Goal;
            }
            if (newFundraiser.CurrentAmount == null)
            {
                newFundraiser.CurrentAmount = currentFundraiser.CurrentAmount;
            }
            if (newFundraiser.Active == currentFundraiser.Active)
            {
                newFundraiser.Active = currentFundraiser.Active;
            }
            if (newFundraiser.Link == null)
            {
                newFundraiser.Link = currentFundraiser.Link;
            }
            if (newFundraiser.Title == null)
            {
                newFundraiser.Title = currentFundraiser.Title;
            }
            if (newFundraiser.Description == null)
            {
                newFundraiser.Description = currentFundraiser.Description;
            }

            return(_fundraiserRepo.Edit(newFundraiser));
        }
示例#3
0
        public Fundraiser SelectAllbyID(string id)
        {
            //Step 1 -  Define a connection to the database by getting
            //          the connection string from web.config
            string        DBConnect = ConfigurationManager.ConnectionStrings["ShimmerConnectionString"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);

            //Step 2 -  Create a DataAdapter to retrieve data from the database table
            string         sqlStmt = "Select * from Fundraisers Where id=(@paraId)";
            SqlDataAdapter da      = new SqlDataAdapter(sqlStmt, myConn);

            da.SelectCommand.Parameters.AddWithValue("@paraId", id);
            //Step 3 -  Create a DataSet to store the data to be retrieved
            DataSet ds = new DataSet();

            //Step 4 -  Use the DataAdapter to fill the DataSet with data retrieved
            da.Fill(ds);
            int        rec_cnt = ds.Tables[0].Rows.Count;
            Fundraiser obj     = null;

            if (rec_cnt > 0)
            {
                DataRow row          = ds.Tables[0].Rows[0]; // Sql command returns only one record
                int     Fdrid        = Convert.ToInt32(row["Id"]);
                string  orgBy        = row["organisedBy"].ToString();
                string  name         = row["name"].ToString();
                string  desc         = row["description"].ToString();
                double  donationGoal = Convert.ToDouble(row["donationGoal"].ToString());
                string  cat          = row["category"].ToString();
                obj    = new Fundraiser(orgBy, name, desc, donationGoal, cat);
                obj.id = Fdrid;
            }

            return(obj);
        }
示例#4
0
        public int Update(Fundraiser fdR)
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ShimmerConnectionString"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);

            string sqlStmt = "UPDATE Fundraisers SET name = @paraTitle, description = @paraDesc, " +
                             "donationGoal = @paraDonGoal WHERE Id =  @paraId";

            int        result = 0; // Execute NonQuery return an integer value
            SqlCommand sqlCmd = new SqlCommand(sqlStmt, myConn);


            sqlCmd = new SqlCommand(sqlStmt, myConn);

            sqlCmd.Parameters.AddWithValue("@paraTitle", fdR.name);
            sqlCmd.Parameters.AddWithValue("@paraDesc", fdR.description);
            sqlCmd.Parameters.AddWithValue("@paraDonGoal", fdR.donationGoal);
            sqlCmd.Parameters.AddWithValue("@paraId", fdR.id.ToString());

            myConn.Open();
            result = sqlCmd.ExecuteNonQuery();

            myConn.Close();

            return(result);
        }
示例#5
0
        public Fundraiser Update(Fundraiser fundraiser)
        {
            fundraiser.DateLastUpdated = DateTime.Now;
            var updatedFundraiser = _context.Update(fundraiser);

            _context.SaveChanges();
            return(updatedFundraiser.Entity);
        }
示例#6
0
 public void AddFundRaiser(Fundraiser fundraiser)
 {
     if (fundraiser == null)
     {
         throw new ArgumentNullException(nameof(fundraiser));
     }
     context.Fundraisers.Add(fundraiser);
 }
示例#7
0
        public IActionResult SignUp_Donor_Entry(Fundraiser fundraiser)
        {
            if (fundraiser.f_password != fundraiser.f_password1)
            {
                return(RedirectToAction("SignUp_Donor", "Home", new { message = "Passwords do not match. Try again." }));
            }

            MD5 md5 = new MD5CryptoServiceProvider();

            //compute hash from the bytes of text
            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(fundraiser.f_password));

            //get hash result after compute it
            byte[] result = md5.Hash;

            StringBuilder strBuilder = new StringBuilder();

            for (int i = 0; i < result.Length; i++)
            {
                //change it into 2 hexadecimal digits
                //for each byte
                strBuilder.Append(result[i].ToString("x2"));
            }


            string        connection_string = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection        = new SqlConnection(connection_string);

            connection.Open();
            string     query1 = $"Select count(*) from USERS where f_email = '{fundraiser.f_email}' and f_category = 2";
            SqlCommand com1   = new SqlCommand(query1, connection);

            var count = (int)com1.ExecuteScalar();

            if (count != 0)
            {
                return(RedirectToAction("SignUp_Donor", "Home", new { message = "Account already exists with this email!" }));
            }

            //connection.Close();
            ////string query = "SELECT [f_id],[f_name],[f_email],[f_password],[f_phone],[f_about],[f_category] FROM [dbo].[FUNDRAISERS]"
            string     query = "INSERT INTO [dbo].[USERS]([f_name],[f_email],[f_password],[f_category]) VALUES(@name,@email,@password,2)";
            SqlCommand com   = new SqlCommand(query, connection);

            com.Parameters.AddWithValue("@name", fundraiser.f_name);
            com.Parameters.AddWithValue("@email", fundraiser.f_email);
            com.Parameters.AddWithValue("@password", strBuilder.ToString());



            com.ExecuteNonQuery();
            //ViewData["Total_fundraiser"] = count;
            connection.Close();
            return(View(fundraiser));

            //return RedirectToAction("donor_index", "Donor");
        }
        public IActionResult Update_info_fundraiser_password(Fundraiser fundraiser)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            //compute hash from the bytes of text
            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(fundraiser.f_password));

            //get hash result after compute it
            byte[] result = md5.Hash;

            StringBuilder strBuilder = new StringBuilder();

            for (int i = 0; i < result.Length; i++)
            {
                //change it into 2 hexadecimal digits
                //for each byte
                strBuilder.Append(result[i].ToString("x2"));
            }

            string        connection_string = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection        = new SqlConnection(connection_string);

            connection.Open();
            string     f_pass = fundraiser.f_password;
            var        f_id   = fundraiser.f_id;
            string     query1 = $"Select count(*) from USERS where f_id = {f_id} and f_password='******'";
            SqlCommand com1   = new SqlCommand(query1, connection);

            var count = (int)com1.ExecuteScalar();

            if (count == 1)
            {
                MD5 md52 = new MD5CryptoServiceProvider();

                //compute hash from the bytes of text
                md52.ComputeHash(ASCIIEncoding.ASCII.GetBytes(fundraiser.f_password1));

                //get hash result after compute it
                byte[] result2 = md52.Hash;

                StringBuilder strBuilder2 = new StringBuilder();
                for (int i = 0; i < result.Length; i++)
                {
                    //change it into 2 hexadecimal digits
                    //for each byte
                    strBuilder2.Append(result2[i].ToString("x2"));
                }
                string     query = $"Update FUNDRAISERS set f_password=@password where f_id={f_id}";
                SqlCommand com   = new SqlCommand(query, connection);
                com.Parameters.AddWithValue("@password", strBuilder2.ToString());
                com.ExecuteNonQuery();
            }
            connection.Close();
            //return RedirectToAction("Create_event_entry","Fundraiser");
            return(RedirectToAction("fundraiser_index", "Fundraiser", new { id = f_id }));
        }
示例#9
0
        public IActionResult donor_index(int id)
        {
            var fr = JsonConvert.DeserializeObject <Fundraiser>(HttpContext.Session.GetString("FundraiserSession"));

            ViewBag.d_name = fr.f_name;
            ViewBag.d_id   = fr.f_id;

            string        connection_string1 = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection1        = new SqlConnection(connection_string1);

            connection1.Open();
            string     query1 = $"select sum(amount) from DONATED where d_id = {fr.f_id}";
            SqlCommand com1   = new SqlCommand(query1, connection1);
            var        count  = 0;

            if (Convert.IsDBNull(com1.ExecuteScalar()))
            {
                count = 0;
            }
            else
            {
                count = (int)com1.ExecuteScalar();
            }
            ViewData["total_amount"] = count;
            //ViewData["message"] = message;
            connection1.Close();

            string        connection_string = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection        = new SqlConnection(connection_string);

            connection.Open();
            string     query = $"select * from USERS where f_id = {id}";
            SqlCommand com   = new SqlCommand(query, connection);


            //string connection_string1 = configuration.GetConnectionString("DefaultConnectionString");
            using (SqlConnection conn = new SqlConnection(connection_string))

            {
                conn.Open();
                SqlDataReader rdr = com.ExecuteReader();
                while (rdr.Read())
                {
                    var f = new Fundraiser();
                    ViewBag.f_id   = (int)rdr["f_id"];
                    f.f_id         = (int)rdr["f_id"];
                    f.f_email      = (string)rdr["f_email"];
                    f.f_password   = (string)rdr["f_password"];
                    f.f_name       = (string)rdr["f_name"];
                    ViewBag.f_name = (string)rdr["f_name"];
                    return(View(f));
                }
                conn.Close();
            }
            return(View(fr));
        }
        public IActionResult Log_out()
        {
            var fr = new Fundraiser()
            {
                f_id = 0, f_name = "", f_email = "", f_password = "", f_phone = "", f_about = ""
            };

            HttpContext.Session.SetString("FundraiserSession", JsonConvert.SerializeObject(fr));
            return(RedirectToAction("Index", "Home"));
        }
示例#11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Session["DonationId"].ToString();

            lblID.Text = id;
            Fundraiser fdR     = new Fundraiser();
            Fundraiser fdRList = fdR.GetFdById(id);

            lblName.Text     = fdRList.name;
            lblOrgBy.Text    = fdRList.organisedBy;
            lblDesc.Text     = fdRList.description;
            lblDonGoal.Text  = fdRList.donationGoal.ToString();
            lblCategory.Text = fdRList.category;
        }
示例#12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         string     id  = Session["DonationId"].ToString();
         Fundraiser obj = new Fundraiser();
         Fundraiser fdR = obj.GetFdById(id);
         lblId.Text     = id;
         lblOrgBy.Text  = fdR.organisedBy.ToString();
         tbFdrName.Text = fdR.name.ToString();
         tbDesc.Text    = fdR.description.ToString();
         tbDonGoal.Text = fdR.donationGoal.ToString();
     }
 }
示例#13
0
        internal Fundraiser Create(Fundraiser FundraiserData)
        {
            string sql = @"
        INSERT INTO fundraiser
            (active, title, description, link, goal, currentAmount, organizationId)
            VALUES
            (@Active, @Title, @Description, @Link, @Goal, @CurrentAmount, @OrganizationId);
            SELECT LAST_INSERT_ID();
            ";
            int    id  = _db.ExecuteScalar <int>(sql, FundraiserData);

            FundraiserData.Id = id;
            return(FundraiserData);
        }
示例#14
0
        public Fundraiser Create(string name, Guid campaignId, FundraiserType type, string creatorUserId, JObject extendedData = null)
        {
            var fundraiser = new Fundraiser {
                Name = name, CampaignId = campaignId, FundraiserType = type, CreatorUserId = creatorUserId, DateCreated = DateTime.Now, DateLastUpdated = DateTime.Now
            };

            if (extendedData != null)
            {
                fundraiser.ExtendedData = extendedData;
            }
            _context.Fundraisers.Add(fundraiser);
            _context.SaveChanges();
            return(fundraiser);
        }
示例#15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Fundraiser fdR = new Fundraiser();

            fdList = fdR.GetAllFd();
            DSFr   = fdR.GetDSFundraiser();

            // using gridview to bind to the list of Fundraiser objects
            GvDonation.Visible    = true;
            GvDonation.DataSource = fdList;
            GvDonation.DataBind();

            RptDonations.DataSource = DSFr;
            RptDonations.DataBind();
        }
示例#16
0
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         Fundraiser newFR  = new Fundraiser();
         int        result = newFR.deleteForFundraiser(Session["DonationId"].ToString());
         lblSuccess.Text   = "Fundraiser has been deleted successfully";
         btnReturn.Visible = false;
         Response.Redirect("Donations.aspx");
     }
     catch
     {
         lblError.Text = "Error";
     }
 }
示例#17
0
        private void Init()
        {
            var builder = new DbContextOptionsBuilder <FundraiseContext>()
                          .UseInMemoryDatabase("FundraiseTestDB");

            var context = new FundraiseContext(builder.Options);

            _donationRepository = new DonationRepository(context);

            var campaignRepository = new CampaignRepository(context);

            _testCampaign = campaignRepository.Create("test", "USD", null, null);

            var fundraiserRepository = new FundraiserRepository(context);

            _testFundraiser = fundraiserRepository.Create("test", _testCampaign.Id, FundraiserType.Individual, "test");
        }
示例#18
0
        internal Fundraiser Edit(Fundraiser newFundraiser)
        {
            string sql = @"
        UPDATE fundraiser
        SET
            goal = @Goal,
            currentAmount = @CurrentAmount,
            active = @Active,
            link = @Link,
            title = @Title,
            description = @Description,
        WHERE id = @Id;
        SELECT * FROM fundraiser WHERE  id = @Id && email = @Email;
            ";

            return(_db.ExecuteScalar <Fundraiser>(sql, newFundraiser));
        }
示例#19
0
        public IActionResult Update_info_donor(Fundraiser fundraiser)
        {
            string        connection_string = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection        = new SqlConnection(connection_string);

            connection.Open();
            var        f_id  = fundraiser.f_id;
            string     query = $"Update USERS set f_name=@name, f_email=@email where f_id={f_id}";
            SqlCommand com   = new SqlCommand(query, connection);

            com.Parameters.AddWithValue("@name", fundraiser.f_name);
            com.Parameters.AddWithValue("@email", fundraiser.f_email);
            com.ExecuteNonQuery();

            connection.Close();
            return(RedirectToAction("donor_index", "Donor", new { id = f_id }));
        }
示例#20
0
        protected void Btn_Submit_Click(object sender, EventArgs e)
        {
            try
            {
                Fundraiser newFR = new Fundraiser();
                newFR.name         = TB_Name.Text;
                newFR.description  = TB_Desc.Text;
                newFR.donationGoal = Convert.ToDouble(TB_DGoal.Text);
                newFR.category     = DDL_Category.SelectedValue;

                newFR.insertFundraiser(newFR);

                Lbl_success.Text = "New Fundraiser created!";
            }
            catch
            {
                Lbl_err.Text = "Error";
            }
        }
 public ActionResult <Fundraiser> Edit(int id, [FromBody] Fundraiser Organization)
 {
     try
     {
         Organization.Id = id;
         string nameIdentifier = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         if (nameIdentifier != null)
         {
             return(Ok(value: _FundraiserService.Edit(Organization)));
         }
         else
         {
             throw new UnauthorizedAccessException("Unauthorized");
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
 public ActionResult <Fundraiser> Create([FromBody] Fundraiser Fundraiser)
 {
     try
     {
         string nameIdentifier = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         if (nameIdentifier != null)
         {
             // Fundraiser.Email = nameIdentifier;
             return(Ok(_FundraiserService.Create(Fundraiser)));
         }
         else
         {
             throw new UnauthorizedAccessException("Unothorized");
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#23
0
        public int Insert(Fundraiser FR)
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ShimmerConnectionString"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);

            int        result  = 0;
            string     sqlstmt = "Insert into Fundraisers(name, description, donationGoal, category) Values(@paraName, @paraDesc, @paraGoal, @paraCategory)";
            SqlCommand sqlCmd  = new SqlCommand(sqlstmt, myConn);

            sqlCmd.Parameters.AddWithValue("@paraName", FR.name);
            sqlCmd.Parameters.AddWithValue("@paraDesc", FR.description);
            sqlCmd.Parameters.AddWithValue("@paraGoal", FR.donationGoal);
            sqlCmd.Parameters.AddWithValue("@paraCategory", FR.category);

            myConn.Open();
            result = sqlCmd.ExecuteNonQuery();

            myConn.Close();

            return(result);
        }
        public IActionResult Update_info_fundraiser(Fundraiser fundraiser)
        {
            string        connection_string = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection        = new SqlConnection(connection_string);

            connection.Open();
            var        f_id  = fundraiser.f_id;
            string     query = $"Update USERS set f_name=@name, f_email=@email, f_about=@about, f_phone=@phone where f_id={f_id}";
            SqlCommand com   = new SqlCommand(query, connection);

            com.Parameters.AddWithValue("@name", fundraiser.f_name);
            com.Parameters.AddWithValue("@email", fundraiser.f_email);
            com.Parameters.AddWithValue("@phone", fundraiser.f_phone);
            com.Parameters.AddWithValue("@about", fundraiser.f_about);

            com.ExecuteNonQuery();

            connection.Close();
            //return View();
            //return RedirectToAction("Create_event_entry","Fundraiser");
            return(RedirectToAction("fundraiser_index", "Fundraiser", new { id = f_id }));
        }
示例#25
0
        public IFundraiserCommandResponse GetFundraiser(string organismReference, string fundraiserReference)
        {
            if (string.IsNullOrWhiteSpace(organismReference) || string.IsNullOrWhiteSpace(fundraiserReference))
            {
                return(new FundraiserCommandResponse(CommandStatus.BAD_PARAMETER, "all parameter are mandatory", null));
            }

            var organism = new GetOrganismCommand().GetOrganism(organismReference);

            if (organism.Status != CommandStatus.DONE)
            {
                return(new FundraiserCommandResponse(organism.Status, organism.Message, null));
            }

            if (organismReference == "1" && fundraiserReference != "1")
            {
                return(new FundraiserCommandResponse(CommandStatus.NOT_FOUND, "This fundraiser doesn't exist", null));
            }

            var options = new List <IActionOption>();
            var infos   = new List <IDynamicInfos>();

            infos.Add(new DynamicInfos("1", "Numéro d'étudiant", null, true));
            options.Add(new ActionOption("1", "Tarif étudiant", "C'est un tarif réduit pour les étudiants", 10, infos));
            options.Add(new ActionOption("2", "Plein tarif", "C'est le tarif normal", 20, null));
            infos = new List <IDynamicInfos>();
            infos.Add(new DynamicInfos("2", "Pourquoi êtes-vous si généreux ?", null, true));
            infos.Add(new DynamicInfos("3", "Combien gagnez-vous par mois", "C'est juste comme ça !", false));
            options.Add(new ActionOption("3", "Généreux", "Comme le plein tarif mais vous êtes généreux", 100, infos));

            var fundraiser = new Fundraiser(fundraiserReference, "collecte-" + fundraiserReference,
                                            "Collecte " + fundraiserReference,
                                            "Ceci est la description de la collecte " + fundraiserReference + " de l'association " +
                                            organismReference, "col-picture-" + organismReference + "-" + fundraiserReference + ".jpg",
                                            options, 10);

            return(new FundraiserCommandResponse(CommandStatus.DONE, null, fundraiser));
        }
示例#26
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         double     donationGoal = Convert.ToDouble(tbDonGoal.Text);
         Fundraiser newFR        = new Fundraiser(lblOrgBy.Text, tbFdrName.Text, tbDesc.Text, donationGoal, "0");
         newFR.id = Convert.ToInt32(lblId.Text);
         int result = newFR.updateForFundraiser();
         if (result == 1)
         {
             lblSuccess.Text = "Fundraiser Updated";
             Response.Redirect("Donations.aspx");
         }
         else
         {
             lblError.Text = "Error";
         }
     }
     catch
     {
         lblError.Text = "Error";
     }
 }
        public IActionResult fundraiser_index(int id)
        {
            var fr = JsonConvert.DeserializeObject <Fundraiser>(HttpContext.Session.GetString("FundraiserSession"));
            //return View(fr);

            string        connection_string = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection        = new SqlConnection(connection_string);

            connection.Open();
            string query = $"select * from USERS where f_id = {id}";

            SqlCommand com = new SqlCommand(query, connection);

            using (SqlConnection conn = new SqlConnection(connection_string))
            {
                conn.Open();
                SqlDataReader rdr = com.ExecuteReader();
                while (rdr.Read())
                {
                    var f = new Fundraiser();
                    ViewBag.fun_id   = (int)rdr["f_id"];
                    f.f_id           = (int)rdr["f_id"];
                    f.f_email        = (string)rdr["f_email"];
                    f.f_password     = (string)rdr["f_password"];
                    f.f_phone        = (string)rdr["f_phone"];
                    f.f_about        = (string)rdr["f_about"];
                    f.f_name         = (string)rdr["f_name"];
                    ViewBag.fun_name = (string)rdr["f_name"];
                    return(View(f));
                }
                conn.Close();
            }

            //return RedirectToAction("Index", "Home");
            return(View(fr));
        }
示例#28
0
        public List <Fundraiser> SelectAll()
        {
            //Step 1 -  Define a connection to the database by getting
            //          the connection string from web.config
            string        DBConnect = ConfigurationManager.ConnectionStrings["ShimmerConnectionString"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);

            //Step 2 -  Create a DataAdapter to retrieve data from the database table
            string         sqlStmt = "Select * from Fundraisers";
            SqlDataAdapter da      = new SqlDataAdapter(sqlStmt, myConn);
            //Step 3 -  Create a DataSet to store the data to be retrieved
            DataSet ds = new DataSet();

            //Step 4 -  Use the DataAdapter to fill the DataSet with data retrieved
            da.Fill(ds);

            //Step 5 -  Read data from DataSet to List
            List <Fundraiser> FdrList = new List <Fundraiser>();
            int rec_cnt = ds.Tables[0].Rows.Count;

            for (int i = 0; i < rec_cnt; i++)
            {
                DataRow    row          = ds.Tables[0].Rows[i]; // Sql command returns only one record
                int        Fdrid        = Convert.ToInt32(row["Id"]);
                string     orgBy        = row["organisedBy"].ToString();
                string     name         = row["name"].ToString();
                string     desc         = row["description"].ToString();
                double     donationGoal = Convert.ToDouble(row["donationGoal"].ToString());
                string     cat          = row["category"].ToString();
                Fundraiser obj          = new Fundraiser(orgBy, name, desc, donationGoal, cat);
                obj.id = Fdrid;
                FdrList.Add(obj);
            }

            return(FdrList);
        }
示例#29
0
        public IActionResult SignIn_Panel(Fundraiser fundraiser)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            //compute hash from the bytes of text
            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(fundraiser.f_password));

            //get hash result after compute it
            byte[] result = md5.Hash;

            StringBuilder strBuilder = new StringBuilder();

            for (int i = 0; i < result.Length; i++)
            {
                //change it into 2 hexadecimal digits
                //for each byte
                strBuilder.Append(result[i].ToString("x2"));
            }

            string        connection_string = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection        = new SqlConnection(connection_string);

            connection.Open();
            string     query = "Select * from USERS where f_email = @email and f_password = @password";
            SqlCommand com   = new SqlCommand(query, connection);

            com.Parameters.AddWithValue("@email", fundraiser.f_email);
            com.Parameters.AddWithValue("@password", strBuilder.ToString());

            SqlDataReader dr = com.ExecuteReader();

            if (dr.Read())
            {
                var f_id = (int)dr["f_id"];
                var cat  = (int)dr["f_category"];
                if (cat == 1)
                {
                    var fr = new Fundraiser()
                    {
                        f_id = (int)dr["f_id"], f_name = (string)dr["f_name"], f_email = (string)dr["f_email"], f_password = (string)dr["f_password"], f_phone = (string)dr["f_phone"], f_about = (string)dr["f_about"]
                    };
                    HttpContext.Session.SetString("FundraiserSession", JsonConvert.SerializeObject(fr));
                    connection.Close();
                    //return View();
                    return(RedirectToAction("fundraiser_index", "Fundraiser", new { id = f_id }));
                }
                else
                {
                    var dnr = new Fundraiser()
                    {
                        f_id = (int)dr["f_id"], f_name = (string)dr["f_name"], f_email = (string)dr["f_email"], f_password = (string)dr["f_password"]
                    };
                    HttpContext.Session.SetString("FundraiserSession", JsonConvert.SerializeObject(dnr));
                    connection.Close();
                    //return View();
                    return(RedirectToAction("Index", "Donor"));
                }
            }

            dr.Close();


            connection.Close();
            ViewBag.error_message = "Email or password did not match! Try again.";
            //ViewData["error_message"] = "Email or password did not match! Try again.";

            return(RedirectToAction("SignIn", "Home", new { message = "Email or password did not match! Try again." }));
        }
 internal Fundraiser Create(Fundraiser Fundraiser)
 {
     return(_fundraiserRepo.Create(Fundraiser));
 }