コード例 #1
0
 private static async Task<StatusResult<Community>> InsertNewCommunityAsync(Community community)
 {
     try
     {
         var db = BottleRocketDbContext.Create();
         db.Communities.Add(community);
         await db.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         return StatusResult<Community>.Error(ex.Message);
     }
     return StatusResult<Community>.Success(community);
 }
コード例 #2
0
        public static async Task<StatusResult<Community>> CreateCommunityAsync(string cname)
        {
            // check if community exist before adding
            var comCheck = await GetCommunityAsync(cname);
            if (comCheck.Code == StatusCode.OK && comCheck.Result != null)
            {
                // if community is found, return it with an error
                return StatusResult<Community>.Error("Community already exist", comCheck.Result);
            }

            // beyond this point implies a new community, so insert a new one
            Community community = new Community()
            {
                Name = cname,
                DateCreated = DateTime.UtcNow,
                LastUpdated = DateTime.UtcNow
            };
            return await InsertNewCommunityAsync(community);
        }