コード例 #1
0
        public async Task <ActionResult> CreateSubCommunity(string subCommunityName, List <String> selectedStreetFloorIDArray, int CommunityId)
        {
            SubCommunitiesController subCommunitiesController = new SubCommunitiesController();
            Response <SubCommunity>  responseSubCommunity     = new Response <SubCommunity>();
            SubCommunity             subCommunity             = new SubCommunity();

            subCommunity.communityID = CommunityId;
            subCommunity.name        = subCommunityName;
            responseSubCommunity     = await subCommunitiesController.PostSubCommunity(subCommunity);



            SubCommunitySelectedStreetFloorsController subCommunitySelectedStreetFloorsController = new SubCommunitySelectedStreetFloorsController();

            if (responseSubCommunity.model != null)
            {
                foreach (var item in selectedStreetFloorIDArray)
                {
                    SubCommunitySelectedStreetFloor subCommunitySelectedStreetFloor = new SubCommunitySelectedStreetFloor();
                    subCommunitySelectedStreetFloor.communityStreetFloorId = Convert.ToInt32(item);
                    subCommunitySelectedStreetFloor.subCommunityId         = responseSubCommunity.model.id;

                    await subCommunitySelectedStreetFloorsController.PostSubCommunitySelectedStreetFloor(subCommunitySelectedStreetFloor);
                }
            }


            return(Json(new{ Status = "Success" }));
        }
コード例 #2
0
        public async Task <IHttpActionResult> PutSubCommunity(int id, SubCommunity subCommunity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != subCommunity.id)
            {
                return(BadRequest());
            }

            db.Entry(subCommunity).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public async Task <IHttpActionResult> GetSubCommunity(int id)
        {
            SubCommunity subCommunity = await db.SubCommunities.FindAsync(id);

            if (subCommunity == null)
            {
                return(NotFound());
            }

            return(Ok(subCommunity));
        }
コード例 #4
0
        public async Task <IHttpActionResult> DeleteSubCommunity(int id)
        {
            SubCommunity subCommunity = await db.SubCommunities.FindAsync(id);

            if (subCommunity == null)
            {
                return(NotFound());
            }

            db.SubCommunities.Remove(subCommunity);
            await db.SaveChangesAsync();

            return(Ok(subCommunity));
        }
コード例 #5
0
        public async Task <Response <SubCommunity> > PostSubCommunity(SubCommunity subCommunity)
        {
            Response <SubCommunity> responseSubCommunity = new Response <SubCommunity>();

            if (!ModelState.IsValid)
            {
                responseSubCommunity.status = "Failed";
                responseSubCommunity.model  = null;
                return(responseSubCommunity);
            }

            db.SubCommunities.Add(subCommunity);
            await db.SaveChangesAsync();

            responseSubCommunity.status = "Success";
            responseSubCommunity.model  = subCommunity;

            return(responseSubCommunity);
        }