public ActionResult Create(int IdLista) { TarefaEntity tarefaEntity = new TarefaEntity { IdLista = IdLista }; return(View(tarefaEntity)); }
public static bool Cadastrar(DateTime dia, DateTime?diaFinal, List <DiaSemanaEnum> diasSemanas, string titulo, PrioridadeEnum prioridade, TimeSpan hora, string descricao, NotificacaoTempoEnum notificacaoTempo) { try { hora = new TimeSpan(hora.Days, hora.Hours, hora.Minutes, 0); var tarefa = new TarefaEntity(titulo, prioridade, hora, descricao, false, notificacaoTempo, NextIdNotification()); if (DataTarefas.Any(df => df.Dia == dia)) { DataTarefas.Find(df => df.Dia == dia).AddTarefa(tarefa); } else { var dataTarefa = new DataTarefaEntity(dia, new List <TarefaEntity>()); dataTarefa.AddTarefa(tarefa); DataTarefas.Add(dataTarefa); } var dataHoraNotificacao = DataTarefas.Find(df => df.Dia == dia).NotificacaoBaseDateTime(tarefa.Id); if (tarefa.NotificacaoTempo.Minutos != 0) { dataHoraNotificacao = dataHoraNotificacao.AddMinutes(tarefa.NotificacaoTempo.Minutos); } CrossLocalNotifications.Current.Show(titulo, descricao, tarefa.IdNotificacao, dataHoraNotificacao); if (diaFinal.HasValue && diasSemanas != null && diasSemanas.Any(ds => ds.Ativo && ds.Aplicar)) { foreach (var date in Enumerable.Range(0, 1 + diaFinal.Value.Subtract(dia).Days) .Select(offset => dia.AddDays(offset)) .ToList() .FindAll(date => date > dia && diasSemanas.Where(ds => ds.Aplicar && ds.Ativo).Select(ds => ds.Id).Contains(date.DayOfWeek)) ) { var res = Cadastrar(date, null, null, titulo, prioridade, hora, descricao, notificacaoTempo); } } } catch (Exception e) { return(false); } SaveChanges(); return(true); }
public Retorno Insert(TarefaEntity entity) { Retorno retorno = new Retorno(); try { TblTarefa tarefa = new TblTarefa { Id = entity.Id, Nome = entity.Nome, Importante = entity.Importante, Prioridade = entity.Prioridade, Ativo = entity.Ativo, DataAlteracao = DateTime.Now }; using (var uow = new UnitOfWork()) { uow.TarefaRepository.Insert(tarefa); uow.SavaChanges(); var idTarefa = tarefa.Id; TblListaTarefa listaTarefa = new TblListaTarefa { IdLista = entity.IdLista, IdTarefa = idTarefa, DataAlteracao = DateTime.Now }; uow.ListaTarefaRepository.Insert(listaTarefa); uow.SavaChanges(); retorno.Sucesso = true; retorno.Mensagem = Mensagens.MSG_005; } } catch (Exception ex) { retorno.Sucesso = false; retorno.Mensagem = Mensagens.MSG_006; } return(retorno); }
public ActionResult Edit([Bind(Include = "Id,IdLista,Nome,Ativo,Importante,Prioridade,DataAlteracao")] TarefaEntity tarefaEntity) { try { if (ModelState.IsValid) { Retorno retorno = _businessTarefa.Update(tarefaEntity); return(RedirectToAction("Index", new { IdLista = tarefaEntity.IdLista })); } return(View(tarefaEntity)); } catch { return(View()); } }
public ActionResult Create([Bind(Include = "Id,IdLista,IdTarefa,Nome,Importante,Prioridade,Ativo,DataAlteracao")] TarefaEntity tarefaEntity) { try { if (ModelState.IsValid) { Retorno retorno = _businessTarefa.Insert(tarefaEntity); return(RedirectToAction("Index", "Lista")); } return(View(tarefaEntity)); } catch { return(View()); } }
public Retorno Find(int id, int IdLista) { Retorno retorno = new Retorno(); TarefaEntity tarefa = new TarefaEntity(); try { TblTarefa entity; using (var uow = new UnitOfWork()) { entity = uow.TarefaRepository.Find(id); } if (entity != null) { tarefa = new TarefaEntity { Id = entity.Id, IdLista = IdLista, Nome = entity.Nome, Importante = entity.Importante, Prioridade = entity.Prioridade, Ativo = entity.Ativo, DataAlteracao = entity.DataAlteracao }; retorno.Objeto = tarefa; } else { retorno.Objeto = null; retorno.Mensagem = Mensagens.MSG_004; } } catch (Exception ex) { retorno.Sucesso = false; retorno.Mensagem = Mensagens.MSG_006; } return(retorno); }
public Retorno Update(TarefaEntity entity) { Retorno retorno = new Retorno(); try { using (var uow = new UnitOfWork()) { var dado = uow.TarefaRepository.Get(x => x.Id == entity.Id); if (dado != null) { dado.Nome = entity.Nome; dado.Ativo = entity.Ativo; dado.Importante = entity.Importante; dado.Prioridade = entity.Prioridade; dado.DataAlteracao = DateTime.Now; uow.TarefaRepository.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); }