Ejemplo n.º 1
0
        public ActionResult Atualizar(Link entidade)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Link obj = LinkBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(entidade.UniqueKey));
                    if (obj == null)
                    {
                        throw new Exception("Não foi possível localizar o link na base de dados.");
                    }

                    obj.UsuarioExclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                    LinkBusiness.Terminar(obj);

                    entidade.UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                    LinkBusiness.Inserir(entidade);

                    Extensions.GravaCookie("MensagemSucesso", "O Link '" + entidade.Nome + "' foi atualizado com sucesso.", 10);

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Link")
                                      } }));
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException() == null)
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.Message
                                          } }));
                    }
                    else
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.GetBaseException().Message
                                          } }));
                    }
                }
            }
            else
            {
                return(Json(new { resultado = TratarRetornoValidacaoToJSON() }));
            }
        }
Ejemplo n.º 2
0
        public void SetUp()
        {
            _testDataProvider = new TestDataProvider();
            _links            = _testDataProvider.GetLinks().AsQueryable();

            var linkRepository = new Mock <ILinkRepository>();
            var unitOfWork     = new Mock <IUnitOfWork>();
            var urlHepler      = new Mock <UrlHelper>();
            var cookieService  = new Mock <ICookieService>();

            cookieService.Setup(c => c.GetUserId(It.IsAny <HttpRequestMessage>()))
            .Returns(_testDataProvider.GetUserId);
            cookieService.Setup(c => c.StoreUserId(
                                    It.IsAny <HttpResponseMessage>(), It.IsAny <string>(), It.IsAny <Guid>()));

            urlHepler.Setup(u => u.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(
                (string name, object values) =>
            {
                var token = values.GetType().GetProperty("token");
                return($"http://hostname/{token.GetValue(values, null)}");
            });

            var mockDbSet = MockDbSet();

            linkRepository.Setup(r => r.Add(It.IsAny <Link>()));
            linkRepository.Setup(r => r.Update(It.IsAny <Link>()));
            linkRepository.Setup(r => r.All).Returns(mockDbSet.Object);

            unitOfWork.Setup(u => u.LinkRepository).Returns(linkRepository.Object);
            unitOfWork.Setup(u => u.SaveChangesAsync()).Returns(Task.CompletedTask);

            var numberEncodingService = new NumberEncodingService();
            var linkBusiness          = new LinkBusiness(unitOfWork.Object, numberEncodingService);

            _linkController = new LinkController(linkBusiness, cookieService.Object)
            {
                Url     = urlHepler.Object,
                Request = new HttpRequestMessage {
                    RequestUri = new Uri("http://hostname")
                }
            };
        }
Ejemplo n.º 3
0
        public ActionResult Terminar(string UK)
        {
            try
            {
                Guid guidUK = Guid.Parse(UK);
                Link obj    = LinkBusiness.Consulta.FirstOrDefault(p => string.IsNullOrEmpty(p.UsuarioExclusao) && p.UniqueKey.Equals(guidUK));
                if (obj == null)
                {
                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Erro = "Não foi possível excluir o link, pois o mesmo não foi localizado."
                                      } }));
                }
                else
                {
                    obj.UsuarioExclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                    LinkBusiness.Terminar(obj);

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Sucesso = "O link '" + obj.Nome + "' foi excluído com sucesso."
                                      } }));
                }
            }
            catch (Exception ex)
            {
                if (ex.GetBaseException() == null)
                {
                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Erro = ex.Message
                                      } }));
                }
                else
                {
                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          Erro = ex.GetBaseException().Message
                                      } }));
                }
            }
        }
Ejemplo n.º 4
0
        public ActionResult Cadastrar(Link entidade)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    entidade.UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                    LinkBusiness.Inserir(entidade);

                    Extensions.GravaCookie("MensagemSucesso", "O link '" + entidade.Nome + "' foi cadastrado com sucesso.", 10);

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Link")
                                      } }));
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException() == null)
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.Message
                                          } }));
                    }
                    else
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.GetBaseException().Message
                                          } }));
                    }
                }
            }
            else
            {
                return(Json(new { resultado = TratarRetornoValidacaoToJSON() }));
            }
        }
Ejemplo n.º 5
0
 public IEnumerable<Link> GetLinks()
 {
     IReader<Link> business = new LinkBusiness();
     return business.Get();
 }
Ejemplo n.º 6
0
 public Link GetLink(int code)
 {
     IReader<Link> business = new LinkBusiness();
     return business.Get(code);
 }
Ejemplo n.º 7
0
 public void EditLink(Link element, string username, string password)
 {
     IManager<Link> business = new LinkBusiness();
     business.Edit(element, username, password);
 }
Ejemplo n.º 8
0
 public void DeleteLink(int code, string username, string password)
 {
     IManager<Link> business = new LinkBusiness();
     business.Delete(code, username, password);
 }
Ejemplo n.º 9
0
 public int AddLink(Link element, string username, string password)
 {
     IManager<Link> business = new LinkBusiness();
     return business.Add(element, username, password);
 }