Exemple #1
0
        public int AddContributor(Contributor contributor)
        {
            using (MySqlConnection dbConn = new MySqlConnection(_connString))
            {
                dbConn.Open();

                string sql = $@"
INSERT INTO bipc.contributor(contributor_id,
                             first_name,
                             last_name,
                             family_name,
                             status,
                             date_added)
VALUES (bipc.fn_get_nextid('contributor'),
        @firstName,
        @lastName,
        @familyName,
        1,
        now());";

                return(dbConn.Execute(sql,
                                      new
                {
                    @firstName = contributor.FirstName,
                    @lastName = contributor.LastName,
                    @familyName = contributor.FamilyName
                }));
            }
        }
        public IActionResult Add(ChurchLibrary.Model.Contributor contributor)
        {
            var apiContributor = new ApiCallerContributor("http://localhost:8080/");

            if (apiContributor.GetAllFullNames().Contains($"{contributor.LastName}, {contributor.FirstName}"))
            {
                ModelState.AddModelError("Error", "Member already exists");
            }
            else
            {
                try
                {
                    apiContributor.AddContributor(contributor);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error", ex.Message);
                }
            }

            return(View("Add", contributor));
        }
Exemple #3
0
        /// <summary>
        /// Update contributor
        /// </summary>
        /// <param name="contributor"></param>
        public int UpdateContributor(Contributor contributor)
        {
            using (MySqlConnection dbConn = new MySqlConnection(_connString))
            {
                dbConn.Open();

                string sql = $@"UPDATE contributor
   SET first_name = @firstName,
       last_name = @lastName,
       family_name = @familyName,
       date_changed = now()
 WHERE contributor_id = @contributorId AND status = 1;";

                return(dbConn.Execute(sql,
                                      new
                {
                    @firstName = contributor.FirstName,
                    @lastName = contributor.LastName,
                    @familyName = contributor.FamilyName,
                    @contributorId = contributor.Id
                }));
            }
        }