public async Task <IActionResult> PutContributor(int id, Contributor contributor)
        {
            if (id != contributor.ContributorId)
            {
                return(BadRequest($"Invalid update request. Member Id does not match Member details object. Id {id}, contributor.ContributorId {contributor.ContributorId}, {contributor.FirstName}, {contributor.LastName}"));
            }

            contributor.DateChanged = DateTime.UtcNow;

            _context.Entry(contributor).Property(x => x.FirstName).IsModified   = true;
            _context.Entry(contributor).Property(x => x.LastName).IsModified    = true;
            _context.Entry(contributor).Property(x => x.FamilyName).IsModified  = true;
            _context.Entry(contributor).Property(x => x.DateChanged).IsModified = true;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Utils.MemberExists(_context, id))
                {
                    return(NotFound($"Member Id [{id}] is invalid/does not exist"));
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> PutOrganization(int id, Organization organization)
        {
            if (id != organization.OrganizationId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #3
0
        public async Task <IActionResult> PutAccount(int id, Account account)
        {
            if (id != account.AccountId)
            {
                return(BadRequest());
            }

            _context.Entry(account).Property(x => x.AccountNumber).IsModified  = true;
            _context.Entry(account).Property(x => x.AccountName).IsModified    = true;
            _context.Entry(account).Property(x => x.BankName).IsModified       = true;
            _context.Entry(account).Property(x => x.InitialBalance).IsModified = true;
            _context.Entry(account).Property(x => x.DateChanged).IsModified    = true;

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

            return(NoContent());
        }
Beispiel #4
0
        public async Task <IActionResult> PutIndustry(int id, Industry industry)
        {
            if (id != industry.IndustryId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutOrganizationCategory(int id, OrganizationCategory organizationCategory)
        {
            if (id != organizationCategory.OrganizationCategoryId)
            {
                return(BadRequest($"Invalid request. ID {id}, OrgCat {organizationCategory.OrganizationCategoryId}"));
            }

            if (!OrganizationCategoryExists(id))
            {
                return(BadRequest("Org Category Id does not exist"));
            }

            if (string.IsNullOrWhiteSpace(organizationCategory.CategoryName))
            {
                return(BadRequest("Category name cannot be empty"));
            }

            if (_context.OrganizationCategory.Any(x => x.OrganizationId == organizationCategory.OrganizationId &&
                                                  x.OrganizationCategoryId != organizationCategory.OrganizationCategoryId &&
                                                  x.CategoryName.Equals(organizationCategory.CategoryName)))
            {
                return(BadRequest("Category name already exists"));
            }

            if (string.IsNullOrWhiteSpace(organizationCategory.UserChanged))
            {
                return(BadRequest("User Login id cannot be empty"));
            }

            organizationCategory.DateChanged = DateTime.UtcNow;

            _context.Entry(organizationCategory).Property(x => x.CategoryName).IsModified = true;
            _context.Entry(organizationCategory).Property(x => x.DateChanged).IsModified  = true;
            _context.Entry(organizationCategory).Property(x => x.UserChanged).IsModified  = true;

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

            return(NoContent());
        }
        public async Task <ActionResult <UserOrganization> > PostUserOrganization(UserOrganization userOrganization)
        {
            if (userOrganization.AuthUserId == 0)
            {
                return(BadRequest("Auth User Id cannot be empty"));
            }

            if (userOrganization.OrganizationId == 0)
            {
                return(BadRequest("Organization Id cannot be empty"));
            }

            if (string.IsNullOrWhiteSpace(userOrganization.UserAdded))
            {
                return(BadRequest("User added cannot be empty"));
            }

            userOrganization.DateAdded          = DateTime.UtcNow;
            userOrganization.UserOrganizationId = await Utils.GetNextIdAsync(_context, "user_organization");

            _context.UserOrganization.Add(userOrganization);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUserOrganization", new { id = userOrganization.UserOrganizationId }, userOrganization));
        }
Beispiel #7
0
        public async static Task <int> GetNextIdAsync(IronChurchContext dbContext, string table_name)
        {
            var tableNextIDObject = await dbContext.SeqControl.Where(x => x.ObjName == table_name).FirstOrDefaultAsync();

            tableNextIDObject.NextId += 1;
            dbContext.Entry(tableNextIDObject).Property(x => x.NextId).IsModified = true;
            await dbContext.SaveChangesAsync();

            return(tableNextIDObject.NextId);
        }
Beispiel #8
0
        public static int GetNextId(IronChurchContext dbContext, string table_name)
        {
            var nextId        = dbContext.SeqControl.Where(x => x.ObjName == table_name).FirstOrDefault().NextId + 1;
            var newSeqcontrol = new SeqControl()
            {
                ObjName = "table_name", NextId = nextId
            };

            dbContext.Entry(newSeqcontrol).Property(x => x.NextId).IsModified = true;
            dbContext.SaveChangesAsync();

            return(nextId);
        }