예제 #1
0
        public static void AddDateControl(double price, DateTime initialDateControl, DateTime finalDateControl)
        {
            ValidityDateControl validityDateControl = new ValidityDateControl(price, initialDateControl, finalDateControl);

            ValidityDateControlModel.Insert(validityDateControl);
            listDates.Add(validityDateControl);
        }
 public static void RemoveItens()
 {
     ValidityControl.UpdateListDatesFromDB();
     foreach (ValidityDateControl tmp in ValidityControl.GetListDates())
     {
         ValidityDateControlModel.Delete(tmp);
     }
     ValidityControl.ClearListDates();
 }
예제 #3
0
 public static void UpdateDateControl(ValidityDateControl dateControl)
 {
     if (dateControl.ID == 0)
     {
         throw new NotFoundIDEntity("Para atualizar um objeto precisa da sua chave primaria");
     }
     ValidityDateControlModel.Update(dateControl);
     UpdateListDatesFromDB();
 }
        public void test01()
        {
            DateTime initialDateControl = new DateTime(2015, 8, 16, 0, 0, 0);
            DateTime finalDateControl   = new DateTime(2015, 11, 15, 23, 59, 59);
            double   price = 5;

            ValidityDateControl dateControl = new ValidityDateControl(price, initialDateControl, finalDateControl);

            //Insert
            ValidityDateControlModel.Insert(dateControl);
            //Select initial date
            ValidityDateControl dateControlSelected = ValidityDateControlModel.Select(initialDateControl);

            Assert.IsTrue(DateTime.Compare(dateControl.InitialDate, dateControlSelected.InitialDate) == 0 &&
                          DateTime.Compare(dateControl.FinalDate, dateControlSelected.FinalDate) == 0 &&
                          dateControl.HourPrice == dateControlSelected.HourPrice, "Houve um erro, datas diferentes");

            //Select by id
            dateControlSelected = ValidityDateControlModel.Select(dateControlSelected.ID);
            Assert.IsTrue(DateTime.Compare(dateControl.InitialDate, dateControlSelected.InitialDate) == 0 &&
                          DateTime.Compare(dateControl.FinalDate, dateControlSelected.FinalDate) == 0 &&
                          dateControl.HourPrice == dateControlSelected.HourPrice, "Houve um erro, datas diferentes");

            //Update with exception
            try
            {
                ValidityDateControlModel.Update(dateControl); // tem que depois passar sem id pra gerar uma exceção
                Assert.Fail("Deveria ter gerado uma exceção NotFoundIDEntity quando passa para atualizar sem uma chave primária");
            }
            catch (NotFoundIDEntity e)
            {
                Assert.IsTrue(true);
            }

            //Update
            dateControl.ID        = dateControlSelected.ID;
            dateControl.HourPrice = 7;
            dateControl.FinalDate = new DateTime(2015, 12, 15, 23, 59, 59);
            ValidityDateControlModel.Update(dateControl);
            dateControlSelected = ValidityDateControlModel.Select(dateControlSelected.ID);
            Assert.IsTrue(DateTime.Compare(dateControl.InitialDate, dateControlSelected.InitialDate) == 0 &&
                          DateTime.Compare(dateControl.FinalDate, dateControlSelected.FinalDate) == 0 &&
                          dateControl.HourPrice == dateControlSelected.HourPrice, "Houve um erro, datas diferentes");

            //Delete
            ValidityDateControlModel.Delete(dateControl);
            try
            {
                ValidityDateControlModel.Select(dateControl.ID);
                Assert.Fail("Deveria ter lançado uma exceção pois não deveria existir objeto na base");
            }
            catch (NotExecuteCommandSql e)
            {
                Assert.IsTrue(true);
            }
        }
예제 #5
0
        public ActionResult Update(int id)
        {
            ValidityDateViewModel model = new ValidityDateViewModel();
            ValidityDateControl   date  = ValidityDateControlModel.Select(id);

            model.HourPrice   = date.HourPrice.ToString().Replace(".", ",");
            model.InitialDate = date.InitialDate;
            model.FinalDate   = date.FinalDate;
            return(View(model));
        }
예제 #6
0
 public static void DeleteDateControlById(int id)
 {
     try
     {
         ValidityDateControl dateControl = listDates.Where((ValidityDateControl vdc) => { return(id == vdc.ID); }).First();
         listDates.Remove(dateControl);
         ValidityDateControlModel.Delete(dateControl);
     }
     catch (InvalidOperationException e)
     {
         throw new NotFoundIDEntity("Não encontrou o item para excluir");
     }
 }
예제 #7
0
 // atualiza a lista com informação vinda do banco
 public static void UpdateListDatesFromDB()
 {
     listDates = ValidityDateControlModel.SelectAll();
 }