public CreateClientDayViewModel(DateTime date) { var dayInParsha = ParshaWeek.GetDayInParsha(date).Split(' '); Enum.TryParse(dayInParsha[0], out ParshaWeek.DayBHL dayBHL); (Year, Parsha, Day) = (dayInParsha[2], dayInParsha[1], dayBHL); }
public ActionResult Edit(ParshaWeek week) { week.StartDate = week.StartDate.AddDays(-(int)week.StartDate.DayOfWeek).Date; week.EndDate = week.StartDate.AddDays(6).AddHours(23).AddMinutes(59).AddSeconds(59); db.Entry(week).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(ClientDay day) { try { var weekStart = day.StartTime.AddDays(-(int)day.StartTime.DayOfWeek).Date; var clientId = day.ClientId; var weeks = db.ClientWeeks.Include(w => w.Days).AsEnumerable().Where(w => w.ClientId == clientId && w.StartDate.AddDays(-(int)w.StartDate.DayOfWeek) == weekStart); var week = weeks.SingleOrDefault(w => w.Billed == false); if (week == null) { var parsha = db.ParshaWeeks.SingleOrDefault(p => p.StartDate == weekStart); if (parsha == null) { var newParsha = new ParshaWeek(weekStart); db.ParshaWeeks.Add(newParsha); db.SaveChanges(); parsha = newParsha; } var newWeek = new ClientWeek(clientId, day.StartTime) { ParshaId = parsha.id }; if (weeks.Count() > 0) { newWeek.StartDate = day.StartTime.Date; foreach (var w in weeks) { w.EndDate = w.Days.LastOrDefault().StartTime; } } db.ClientWeeks.Add(newWeek); db.SaveChanges(); week = newWeek; } day.WeekId = week.Id; db.ClientDays.Add(day); db.SaveChanges(); week.SetBalanceDue(); db.SaveChanges(); return(Json("", JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(e.Message, JsonRequestBehavior.AllowGet)); } }
public JsonResult Create(ParshaWeek week) { week.StartDate = week.StartDate.AddDays(-(int)week.StartDate.DayOfWeek).Date; week.EndDate = week.StartDate.AddDays(6).AddHours(23).AddMinutes(59).AddSeconds(59); var parshas = db.ParshaWeeks; if (parshas.Any(p => p.StartDate == week.StartDate)) { throw new Exception(); } db.ParshaWeeks.Add(week); db.SaveChanges(); var parsha = db.ParshaWeeks.Find(week.id); return(Json(parsha, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(CreateClientDayViewModel model) { try { var date = ParshaWeek.GetDateFromPharsha(model.Day, model.Parsha, model.Year); var dateTime = new DateTime(date.Year, date.Month, date.Day, model.StartTime.Hours, model.StartTime.Minutes, 00); var clientDay = new ClientDay(dateTime, model.EndTime, model.ClientId, model.BreakDown, model.PriceId); db.ClientBalances.Find(clientDay.ClientId).Add(clientDay.Price); db.SaveChanges(); return(RedirectToAction("Create", "ClientWeeks", clientDay)); } catch (Exception e) { return(Json(e.Message)); } }
public ActionResult Create() { var week = new ParshaWeek(); return(View(week)); }