public ActionResult CommunityCreate([DataSourceRequest] DataSourceRequest request, CommunityItem communityItem)
 {
     if (communityItem != null && ModelState.IsValid)
     {
         service.CreateCommunity(communityItem);
     }
     return(Json(new[] { communityItem }.ToDataSourceResult(request, ModelState)));
 }
Esempio n. 2
0
        public void Create_Community_Success()
        {
            var res = communityService.CreateCommunity(new CreateCommunity()
            {
                Local    = "Lisboa",
                UserId   = "1",
                Name     = "silicon valey",
                Tags     = new int[] { 3, 7 },
                Sponsors = new int[] { 1 }
            }).Result;

            var res2 = communityService.GetByIdAsync(res.Result).Result;

            Assert.AreEqual(res2.Result.name, "silicon valey");
            Assert.AreEqual(2, res2.Result.tag.Count());
            var id = communityService.DeleteCommunity(new CreateCommunity()
            {
                UserId = "1",
                Id     = res2.Result.id
            }).Result;
        }
Esempio n. 3
0
        public void Should_create_community_when_community_has_valid_data()
        {
            var fakeRepo             = Substitute.For <ICommunityRepository>();
            var createCommunityModel = _fixture.Build <CreateCommunityModel>().Create();

            var community = GetCommunity(createCommunityModel);

            fakeRepo.GetCommunity(Arg.Is <string>(x => x == community.Email)).ReturnsNull();
            var communityService = new CommunityService(fakeRepo);

            communityService.CreateCommunity(createCommunityModel).ConfigureAwait(false);
            fakeRepo.Received(1).GetCommunity(Arg.Is <string>(x => x == community.Email));
            fakeRepo.Received(1).SaveCommunity(Arg.Is <CreateCommunityModel>(x => x.Email == community.Email));
        }
        public async Task <ActionResult> Create(Community community)
        {
            if (ModelState.IsValid)
            {
                CommunityService service = CommunityService.GetInstance();
                //ImageCommunityService imgService = new ImageCommunityService(service);

                CreateCommunity newCommunity = new CreateCommunity()
                {
                    Name           = community.Name,
                    Description    = community.Description,
                    Local          = community.Local,
                    FoundationDate = community.date,
                    Avatar         = community.Avatar == null?null:community.Avatar.InputStream,
                    UserId         = User.Identity.GetUserId(),
                    Latitude       = community.Latitude,
                    Longitude      = community.Longitude
                };
                var res = await service.CreateCommunity(newCommunity);

                if (res.Success)
                {
                    return(RedirectToAction("Get", new { id = community.Name }));
                }
                else
                {
                    ViewBag.Error   = true;
                    ViewBag.Message = res.Message;
                }
                return(View(community));
            }
            else
            {
                return(View(community));
            }
        }