Beispiel #1
0
        public Retorno Insert(ListaEntity entity)
        {
            Retorno retorno = new Retorno();

            try
            {
                TblLista lista = new TblLista
                {
                    Nome          = entity.Nome,
                    Ativo         = entity.Ativo,
                    DataAlteracao = DateTime.Now
                };

                using (var uow = new UnitOfWork())
                {
                    uow.ListaRepository.Insert(lista);
                    uow.SavaChanges();

                    retorno.Sucesso  = true;
                    retorno.Mensagem = Mensagens.MSG_005;
                }
            }
            catch (Exception ex)
            {
                retorno.Sucesso  = false;
                retorno.Mensagem = Mensagens.MSG_006;
            }

            return(retorno);
        }
Beispiel #2
0
        public IHttpActionResult PutListaEntity(int id, ListaEntity listaEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != listaEntity.Id)
            {
                return(BadRequest());
            }

            db.Entry(listaEntity).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ListaEntityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public IHttpActionResult GetListaEntity(int id)
        {
            ListaEntity listaEntity = db.ListaEntities.Find(id);

            if (listaEntity == null)
            {
                return(NotFound());
            }

            return(Ok(listaEntity));
        }
Beispiel #4
0
        public IHttpActionResult PostListaEntity(ListaEntity listaEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _businessLista.Insert(listaEntity);

            return(Ok(listaEntity));

            //return CreatedAtRoute("DefaultApi", new { id = listaEntity.Id }, listaEntity);
        }
Beispiel #5
0
        public IHttpActionResult DeleteListaEntity(int id)
        {
            ListaEntity listaEntity = db.ListaEntities.Find(id);

            if (listaEntity == null)
            {
                return(NotFound());
            }

            db.ListaEntities.Remove(listaEntity);
            db.SaveChanges();

            return(Ok(listaEntity));
        }
Beispiel #6
0
        public ActionResult Edit([Bind(Include = "Id,Nome,Ativo,DataAlteracao")] ListaEntity listaEntity)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Retorno retorno = _businessLista.Update(listaEntity);

                    return(RedirectToAction("Index"));
                }

                return(View(listaEntity));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #7
0
        private async void CriarLista()
        {
            Uri uri = new Uri("http://localhost:63879/api/ListaAPI");

            ListaEntity entity = new ListaEntity();

            entity.Nome  = txtNome.Text;
            entity.Ativo = chkAtivo.Checked;

            using (var client = new HttpClient())
            {
                var serializedLista = JsonConvert.SerializeObject(entity);
                var content         = new StringContent(serializedLista, Encoding.UTF8, "application/json");
                var result          = await client.PostAsync(uri, content);
            }

            GetListas();

            LimparForm();
        }
Beispiel #8
0
        public Retorno Find(int id)
        {
            Retorno retorno = new Retorno();

            ListaEntity lista = new ListaEntity();

            try
            {
                TblLista entity;

                using (var uow = new UnitOfWork())
                {
                    entity = uow.ListaRepository.Find(id);
                }

                if (entity != null)
                {
                    lista = new ListaEntity
                    {
                        Id            = entity.Id,
                        Nome          = entity.Nome,
                        Ativo         = entity.Ativo,
                        DataAlteracao = entity.DataAlteracao
                    };

                    retorno.Objeto = lista;
                }
                else
                {
                    retorno.Objeto   = null;
                    retorno.Mensagem = Mensagens.MSG_004;
                }
            }
            catch (Exception ex)
            {
                retorno.Sucesso  = false;
                retorno.Mensagem = Mensagens.MSG_006;
            }

            return(retorno);
        }
Beispiel #9
0
        public ICommandResult Handler(CreateListaCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Alguma coisa deu errado", command.Notifications));
            }


            var newLista = new ListaEntity(
                command.Name,
                command.Start,
                command.Description,
                Guid.NewGuid().ToString().Substring(0, 7),
                command.Pass,
                command.CriadorId
                );


            _listaRepository.CreateNewLista(newLista);

            return(new GenericCommandResult(true, "Sucesso", newLista));
        }
Beispiel #10
0
        public Retorno Update(ListaEntity entity)
        {
            Retorno retorno = new Retorno();

            try
            {
                using (var uow = new UnitOfWork())
                {
                    var dado = uow.ListaRepository.Get(x => x.Id == entity.Id);

                    if (dado != null)
                    {
                        dado.Nome          = entity.Nome;
                        dado.Ativo         = entity.Ativo;
                        dado.DataAlteracao = DateTime.Now;

                        uow.ListaRepository.Update(dado);
                        uow.SavaChanges();

                        retorno.Sucesso  = true;
                        retorno.Mensagem = Mensagens.MSG_005;
                    }
                    else
                    {
                        retorno.Sucesso  = false;
                        retorno.Mensagem = Mensagens.MSG_004;
                    }
                }
            }
            catch (Exception ex)
            {
                retorno.Sucesso  = false;
                retorno.Mensagem = Mensagens.MSG_006;
            }

            return(retorno);
        }
Beispiel #11
0
 public void DeleteLista(ListaEntity lista)
 {
     _context.Listas.Remove(lista);
     _context.SaveChanges();
 }
Beispiel #12
0
 public void CreateNewLista(ListaEntity lista)
 {
     _context.Listas.Add(lista);
     _context.SaveChanges();
 }