Exemplo n.º 1
0
        public void Handle(CreateLinkCommand command)
        {
            var user = UserRepository.Get(command.UserId);

            Guard.IsNotNull(user, "user");

            var linkType = LinkTypeRepository.Get(command.LinkTypeId);

            Guard.IsNotNull(linkType, "linkType");


            var link = new Link()
            {
                Description  = command.Description,
                Img          = command.Img,
                IsShow       = command.IsShow,
                LinkTxt      = command.LinkTxt,
                LinkUrl      = command.LinkUrl,
                User         = user,
                LinkType     = linkType,
                CreateDate   = DateTime.Now,
                LastDateTime = DateTime.Now
            };

            LinkRepository.Save(link);
        }
Exemplo n.º 2
0
        public void Handle(UpdateLinkCommand command)
        {
            var link = LinkRepository.Get(command.LinkId);

            Guard.IsNotNull(link, "link");
            if (!string.IsNullOrEmpty(command.Description))
            {
                link.Description = command.Description;
            }
            if (!string.IsNullOrEmpty(command.Img))
            {
                link.Img = command.Img;
            }
            if (command.IsShow != null)
            {
                link.IsShow = (bool)command.IsShow;
            }
            if (command.LinkTypeId != null)
            {
                var linkType = LinkTypeRepository.Get((int)command.LinkTypeId);
                Guard.IsNotNull(linkType, "linkType");
                link.LinkType = linkType;
            }

            if (!string.IsNullOrEmpty(command.LinkTxt))
            {
                link.LinkTxt = command.LinkTxt;
            }
            if (!string.IsNullOrEmpty(command.LinkUrl))
            {
                link.LinkUrl = command.LinkUrl;
            }

            link.LastDateTime = DateTime.Now;
            LinkRepository.SaveOrUpdate(link);
        }