public void CreateCommunity()
        {
            int newCommunityID = 0;

            try
            {
                newCommunityID = com.PostAsync(new CreateCommunity()
                {
                    Name = "Break", Local = "rua street", Description = "somos breakers", FoundationDate = DateTime.Now, UserId = "2", Tags = new int[] { 4, 3 }
                }).Result;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentException));
            }
            var res = com.GetByIdAsync(newCommunityID).Result;

            Assert.AreEqual(res.name, "Break");
            Assert.AreEqual(2, res.tag.Count());
            var id = com.DeleteAsync(res).Result;
        }
Esempio n. 2
0
        private async Task <OperationResult <int> > Post(CreateCommunity item)
        {
            if (item.Name == null)
            {
                return new OperationResult <int>()
                       {
                           Success = false, Message = Messages.COMMUNITY_NAME
                       }
            }
            ;
            var user = await userService.GetByIdAsync(item.UserId);

            if (!user.Success)
            {
                return new OperationResult <int>()
                       {
                           Success = false, Message = user.Message
                       }
            }
            ;


            try
            {
                if (item.Tags != null)
                {
                    item.Tags = item.Tags.Distinct().ToArray();
                }
                if (item.Sponsors != null)
                {
                    item.Sponsors = item.Sponsors.Distinct().ToArray();
                }


                string img = (await ImageService.SendToProvider(item.Name, ImageService.ImageIdentity.Communities, item.Avatar, ImageService.ImageType.Avatar)).Result;

                item.AvatarLink = img;
                var id = await communityRepo.PostAsync(item);

                return(new OperationResult <int>()
                {
                    Success = true, Message = Messages.COMMUNITY_CREATED_SUCCESS, Result = id
                });
            }
            catch (Exception ex)
            {
                ImageService.DeleteFolder(item.Name, ImageService.ImageIdentity.Communities);
                return(new OperationResult <int>()
                {
                    Success = false, Message = ex.Message
                });
            }
        }