public void Delete_TimeTable_By_TimeTable()
        {
            string timeTableName = "Test TimeTable to Delete";

            // Add to database
            using (ThamesClipperContext ctx = new ThamesClipperContext())
            {
                TimeTableRepository timeTableRepository = new TimeTableRepository(ctx);
                timeTableRepository.Add(new TimeTable { Name = timeTableName });
                timeTableRepository.SaveChanges();
            }

            // Find and delete it
            using (ThamesClipperContext ctx = new ThamesClipperContext())
            {
                List<TimeTable> timeTables = ctx.TimeTables.Where(pier => pier.Name == timeTableName).ToList();
                Assert.AreEqual(1, timeTables.Count());

                TimeTableRepository timeTableRepository = new TimeTableRepository(ctx);
                timeTableRepository.Delete(timeTables[0]);
                timeTableRepository.SaveChanges();
            }

            // Check that nothing is there
            using (ThamesClipperContext ctx = new ThamesClipperContext())
            {
                List<TimeTable> timeTables = ctx.TimeTables.Where(pier => pier.Name == timeTableName).ToList();
                Assert.AreEqual(0, timeTables.Count());
            }
        }
Exemplo n.º 2
0
 public JsonResult Delete(int id)
 {
     try
     {
         _timeTableRepository.Delete(id);
         return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new { result = e.Message }, JsonRequestBehavior.AllowGet));
     }
 }
        public void Save()
        {
            List <time_table> kiolvasottTimeTableElemek = new List <time_table>();
            List <time_table> torolniTimeTableElemek    = new List <time_table>();

            int selectedYear  = selectedDate.Year;
            int selectedMonth = selectedDate.Month;

            foreach (DataRow row in view.globalTimeTable.Rows)
            {
                if (!string.IsNullOrEmpty(row.ItemArray[view.globalTimeTable.Columns.Count - 1].ToString()))
                {
                    for (int i = 1; i < row.ItemArray.Length - 1; i++)
                    {
                        int      userId        = (int)row.ItemArray[view.globalTimeTable.Columns.Count - 1];
                        string   cellValue     = row.ItemArray[i].ToString();
                        int      selectedDay   = i;
                        DateTime startDate     = new DateTime(selectedYear, selectedMonth, selectedDay);
                        DateTime endDate       = startDate;
                        bool     betegSzabi    = false;
                        bool     fizetettSzabi = false;

                        if (!string.IsNullOrEmpty(cellValue))
                        {
                            switch (cellValue)
                            {
                            case "B":
                                betegSzabi = true;
                                break;

                            case "FSZ":
                                fizetettSzabi = true;
                                break;

                            default:
                                if (cellValue.Contains('-'))
                                {
                                    string[] kezdVeg = cellValue.Split('-');
                                    int      startH  = Convert.ToInt32(kezdVeg[0]);
                                    int      endH    = Convert.ToInt32(kezdVeg[1]);
                                    if (endH < startH)
                                    {
                                        endDate = endDate.AddDays(1);
                                    }
                                    TimeSpan startTime = new TimeSpan(startH, 0, 0);
                                    TimeSpan endTime   = new TimeSpan(endH, 0, 0);
                                    startDate = startDate.Date + startTime;
                                    endDate   = endDate.Date + endTime;
                                }
                                break;
                            }
                            kiolvasottTimeTableElemek.Add(new time_table(userId, startDate, endDate, fizetettSzabi, betegSzabi, DateTime.Now));
                        }
                        else
                        {
                            torolniTimeTableElemek.Add(new time_table(userId, startDate, endDate, fizetettSzabi, betegSzabi, DateTime.Now));
                        }
                    }
                }
            }
            foreach (time_table item in kiolvasottTimeTableElemek)
            {
                if (repoTimeTable.Exists(item))
                {
                    try
                    {
                        repoTimeTable.Update(item);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        repoTimeTable.Insert(item);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                repoTimeTable.Save();
            }

            foreach (time_table item in torolniTimeTableElemek)
            {
                if (repoTimeTable.Exists(item))
                {
                    repoTimeTable.Delete(item);
                }
                repoTimeTable.Save();
            }
        }