Ejemplo n.º 1
0
        public void UpdateCommunity()
        {
            var community = com.GetByIdAsync(2).Result;

            community.description = "somos netpontanos";
            var id         = com.PutAsync(community).Result;
            var community2 = com.GetByIdAsync(2).Result;

            Assert.AreEqual(community.name, "netponto");
            Assert.AreEqual(community.description, "somos netpontanos");

            community.description = "somos fixes";
            var final = com.PutAsync(community).Result;
        }
Ejemplo n.º 2
0
        //<------------------------------------------------------------------------------------------------------>
        //<------------------------------------------------------------------------------------------------------>


        private async Task <OperationResult <int> > Put(CreateCommunity item)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var community = await communityRepo.GetByIdAsync(item.Id);

                if (community == null)
                {
                    return new OperationResult <int>()
                           {
                               Success = false, Message = Messages.COMMUNITY_NOT_EXIST
                           }
                }
                ;
                if (community.admins.FirstOrDefault(user => user.id == item.UserId) == null)
                {
                    return new OperationResult <int>()
                           {
                               Success = false, Message = Messages.USER_NOT_PERMISSION
                           }
                }
                ;

                string img = null;
                if (item.Avatar != null)
                {
                    img = (await ImageService.SendToProvider(item.Name, ImageService.ImageIdentity.Communities, item.Avatar, ImageService.ImageType.Avatar)).Result;
                }
                try
                {
                    community.avatar         = img == null ? community.avatar : img;
                    community.description    = item.Description == null ? community.description : item.Description;
                    community.foundationDate = item.FoundationDate == DateTime.MinValue ? community.foundationDate : item.FoundationDate;
                    community.local          = item.Local == null ? community.local : item.Local;
                    community.site           = item.Site == null ? community.site : item.Site;
                    community.mail           = item.Mail == null ? community.mail : item.Mail;
                    community.gitHub         = item.GitHub == null ? community.gitHub : item.GitHub;

                    var id = await communityRepo.PutAsync(community);

                    scope.Complete();
                    return(new OperationResult <int>()
                    {
                        Success = true, Message = Messages.COMMUNITY_UPDATED_SUCCESS, Result = id
                    });
                }
                catch (Exception ex)
                {
                    return(new OperationResult <int>()
                    {
                        Success = false, Message = ex.InnerException.Message
                    });
                }
            }
        }