Esempio n. 1
0
        public async Task PutCommunityAsync(CommunityV1DTO communityDTO)
        {
            var community = await _context.Community
                            .Where(c => c.CommunityId == communityDTO.CommunityId)
                            .SingleOrDefaultAsync();

            _context.Entry(community).CurrentValues.SetValues(communityDTO);

            await _context.SaveChangesAsync();
        }
Esempio n. 2
0
        public void Community_should_not_have_errors()
        {
            var community = new CommunityV1DTO();

            community.CommunityName        = "valid name";
            community.CommunityDescription = "A valid description";


            var Result = CommunityVal.TestValidate(community);

            Result.ShouldNotHaveValidationErrorFor(x => x.CommunityName);
            Result.ShouldNotHaveValidationErrorFor(x => x.CommunityDescription);
        }
Esempio n. 3
0
        private async Task <Community> EnsureCommunityExistence(CommunityV1DTO cDTO)
        {
            var community = await _context.Community
                            .Where(c => c.CommunityName == cDTO.CommunityName)
                            .SingleOrDefaultAsync();

            if (community == null)
            {
                community = new Community();
                _context.Community.Add(community);
                _context.Entry(community).CurrentValues.SetValues(cDTO);
                await _context.SaveChangesAsync();
            }
            return(community);
        }
Esempio n. 4
0
        public async Task <IActionResult> PutCommunity(int communityId, [FromBody] CommunityV1DTO communityDTO)
        {
            try
            {
                // Check to ensure service exists before calling contextmanager method.
                var community = await _contextManager.GetCommunityByIdAsync(communityId);

                if (community == null)
                {
                    return(NotFound());
                }
                communityDTO.CommunityId = communityId;

                await _contextManager.PutCommunityAsync(communityDTO);

                return(NoContent());
            }
            catch (Exception e)
            {
                throw e;
            }
        }