Exemplo n.º 1
0
 /// <summary>
 /// Copy Constructor.
 /// Creates a new contribution business entity by copying the fields
 /// of another contribution BE.
 /// </summary>
 /// <param name="contribution">The source contribution.</param>
 public ContributionBE(ContributionBE contribution)
 {
     this.contributor = contribution.contributor;
     this.project = contribution.project;
     this.amount = contribution.amount;
     this.date = contribution.date;
 }
Exemplo n.º 2
0
        protected void create_Project(object sender, EventArgs e)
        {
            bool correct = true;

            if (creditsTextboxProject.Text.Length == 0 ||
                Int32.Parse(creditsTextboxProject.Text) > Int32.Parse(Session["UserCredit"].ToString()))
            {
                creditsFeedback.Visible = true;
                correct = false;
            }
            else
                creditsFeedback.Text = "";

            if (correct)
            {
                //Project information.
                String tittle = tittleProjectTextbox.Text;
                String description = descriptionTextbox.Text;
                UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), "");
                UserBE creator = new UserBE(user1.getUserByNick());
                int code = -1;
                DateTime creation = DateTime.Now;
                DateTime expires = DateTime.MinValue;
                int credit = Int32.Parse(creditsTextboxProject.Text);
                DateTime version = DateTime.Now;
                String gitDir = "There";

                //Update the UserBE credits and also the Sessión value.
                String currentCredits = Session["UserCredit"].ToString();
                Session["UserCredit"] = Int32.Parse(currentCredits) - credit;
                creator.Credit = Int32.Parse(currentCredits) - credit;
                creator.update();

                //Project creation.
                ProjectBE crProject = new ProjectBE(tittle, description, creator, code,
                    creation, expires, credit, credit, version, gitDir);
                crProject.create();
                crProject.Code = crProject.getLastCode();

                //When you create a project, you are contributing to it.
                ContributionBE contribution = new ContributionBE(creator, crProject, credit, DateTime.Now);
                contribution.create();

                creationFeedback.Text = "Project created successfully!";
                creationFeedback.ForeColor = System.Drawing.Color.Green;
            }
        }
Exemplo n.º 3
0
        protected void contribute(object sender, EventArgs e)
        {
            if (creditsBox.Text.Length > 2)
            {
                if (Int32.Parse(creditsBox.Text) <= Int32.Parse(Session["UserCredit"].ToString()))
                {
                    //Get the query string parameters.
                    string projectTitle = Session["ProjectTitle"].ToString();
                    int projectCode = Int32.Parse(Session["ProjectCode"].ToString());
                    int credits = Int32.Parse(creditsBox.Text);

                    //Create a project and look for the one we are being asked.
                    ProjectBE project = new ProjectBE();
                    project.Code = projectCode;
                    project = project.getByCode();

                    project.Credit = project.Credit + credits;
                    project.PartitionCredit = project.PartitionCredit + credits;

                    project.update();

                    //We need the user, so we update its credits.
                    UserBE usuario = new UserBE();
                    usuario.Email = Session["UserEmail"].ToString();
                    usuario = usuario.getUserByEmail();
                    usuario.Credit = usuario.Credit - credits;
                    usuario.update();
                    Session["UserCredit"] = usuario.Credit;

                    //And we must also create the contribution entry.
                    ContributionBE contr = new ContributionBE(usuario, project, Int32.Parse(creditsBox.Text), DateTime.Now);
                    contr.create();

                    FeedbackCredit.Text = "Done!";
                    projectProfileLabelCredits.Text = project.Credit.ToString();
                    FeedbackCredit.Visible = true;
                }
                else
                {
                    FeedbackCredit.Text = "Wrong quantity.";
                    FeedbackCredit.Visible = true;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Contribution Update.
        /// Updates the database register which matches the given
        /// contribution replacing all the database fields with
        /// the ones of the provided contribution.
        /// </summary>
        /// <param name="contribution">The "source" contribution that will be updated.</param>
        public void update(ContributionBE contribution)
        {
            SqlConnection c = new SqlConnection(connection);

            try
            {
                c.Open();

                SqlParameter project = new SqlParameter();
                project.ParameterName = "@project";
                project.Value = contribution.Project.Code;
                SqlParameter usr = new SqlParameter();
                usr.ParameterName = "@usr";
                usr.Value = contribution.Contributor.Email;
                SqlParameter date = new SqlParameter();
                date.ParameterName = "@date";
                date.Value = contribution.Date.ToString("dd/MM/yyyy");
                SqlParameter amount = new SqlParameter();
                amount.ParameterName = "@amount";
                amount.Value = contribution.Amount.ToString();

                SqlCommand com = new SqlCommand("UPDATE contributions " +
                    "SET project=@project, usr=@usr, date=@date, amount=@amount " +
                    "WHERE project=@project AND usr=@usr AND date=@date", c);

                com.Parameters.Add(project);
                com.Parameters.Add(usr);
                com.Parameters.Add(date);
                com.Parameters.Add(amount);

                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                // Show message box
            }
            finally
            {
                c.Close();
            }
        }
Exemplo n.º 5
0
        // /////////////////////////////////////////////////////////////////////
        // Methods /////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Contribution Insertion.
        /// Inserts the given contribution in the database building the adequate
        /// query and handling the possible SQL errors that can occur when performing
        /// the query. 
        /// </summary>
        /// <param name="contribution">The contribution to be inserted.</param>
        /// <returns>A string which contains an error/success message.</returns>
        public string insert(ContributionBE contribution)
        {
            // We will be using the connected access model.

            string result = "The contribution has been succesfully added!";

            SqlConnection c = new SqlConnection(connection);

            try
            {
                c.Open();

                SqlParameter project = new SqlParameter();
                project.ParameterName = "@project";
                project.Value = contribution.Project.Code;
                SqlParameter usr = new SqlParameter();
                usr.ParameterName = "@usr";
                usr.Value = contribution.Contributor.Email;
                SqlParameter date = new SqlParameter();
                date.ParameterName = "@date";
                date.Value = contribution.Date.ToString("G");
                SqlParameter amount = new SqlParameter();
                amount.ParameterName = "@amount";
                amount.Value = contribution.Amount.ToString();

                SqlCommand com = new SqlCommand("INSERT INTO contributions (project, usr, date, amount)" +
                    "VALUES (@project, @usr, @date, @amount)", c);

                com.Parameters.Add(project);
                com.Parameters.Add(usr);
                com.Parameters.Add(date);
                com.Parameters.Add(amount);

                com.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                if (ex.Message.Contains("PRIMARY KEY"))
                    result = "ERROR: A contribution has already been made today for that project.";
            }
            catch (Exception exg)
            {
                result = "ERROR: Unknown error, try it again later...";
            }
            finally
            {
                c.Close();
            }

            return result;
        }
Exemplo n.º 6
0
 public void updateContribution(ContributionBE contribution)
 {
     //Do stuff
 }
Exemplo n.º 7
0
 /* ****************************************************************** */
 /* Methods                                                            */
 /* ****************************************************************** */
 public void insertContribution(ContributionBE contribution)
 {
     //Do stuff
 }
Exemplo n.º 8
0
 public void deleteContribution(ContributionBE contribution)
 {
     //Do stuff
 }