public ActionResult Index(CalendarOrder model) { CalendarOrder calOrder = new CalendarOrder(model.OfficeID); if (ModelState.IsValid) { using (CalendarEntities db = new CalendarEntities()) { calOrder.NewOrder = model.NewOrder; Customer _customer = db.Customers.Where(x => x.PersonalNumber.Equals(model.Customer.PersonalNumber)).SingleOrDefault(); //creating customer if not existing if (_customer == null) { _customer = model.Customer; db.Customers.Add(_customer); // ID to _customer automatically added here db.SaveChanges(); } //To get values in detail page calOrder.Customer = _customer; //necessary values to insert calOrder.NewOrder.CustomerID = _customer.ID; calOrder.NewOrder.OfficeID = model.OfficeID; db.Orders.Add(calOrder.NewOrder); db.SaveChanges(); } } return(View("Details", calOrder)); }
public JsonResult SaveEvent(Events events) { var status = false; using (CalendarEntities calendar = new CalendarEntities()) { if (events.EventId > 0) { var eve = calendar.Events.Where(c => c.EventId == events.EventId).FirstOrDefault(); if (eve != null) { eve.EventId = events.EventId; eve.Subject = events.Subject; eve.Start = events.Start; eve.End = events.End; eve.Description = events.Description; eve.IsFullDay = events.IsFullDay; eve.ThemeColor = events.ThemeColor; } } else { calendar.Events.Add(events); } calendar.SaveChanges(); status = true; } return(new JsonResult { Data = new { status = status } }); }
public JsonResult GetEvents() { using (CalendarEntities CE = new CalendarEntities()) { var events = CE.Events.ToList(); return(new JsonResult { Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
/// <summary> /// Gets from DB all procedures that has proper OfficeID and Active==true /// </summary> /// <returns>All procedures that has proper OfficeID and Active==true</returns> public List <Procedure> getActiveProcedures() { List <Procedure> proceduresActive; using (CalendarEntities entities = new CalendarEntities()) { proceduresActive = (from p in entities.Procedures where (p.OfficeID.Equals(OfficeID) && p.Active == true) select p).ToList(); } return(proceduresActive); }
/// <summary> /// Get all orders which meets given conditions. /// Takes every order that has even part in this month. /// </summary> /// <param name="officeID">What officeID shoudl be in orders</param> /// <param name="year">In what year should be order</param> /// <param name="month">In what month should be order</param> /// <returns>List with null if no order. List with orders otherwise</returns> public static List <Order> getAllOrders(int officeID, int year, int month) { List <Order> orders; using (CalendarEntities db = new CalendarEntities()) { orders = (from order in db.Orders where (order.OfficeID.Equals(officeID) && order.Begin.Year.Equals(year) && (order.Begin.Month.Equals(month) || order.End.Month.Equals(month))) select order).ToList(); } return(orders); }
/// <summary> /// Get office with currrent id /// </summary> /// <param name="id">identificator of offici</param> /// <param name="hasToBeActive">if true, looking only for active office</param> /// <returns>null if no (active if hasToBeActive==true) office, instance of Office otherwise</returns> public static Office getOffice(int id, bool hasToBeActive) { Office office; using (CalendarEntities db = new CalendarEntities()) { office = (from off in db.Offices where (off.ID == id) select off).SingleOrDefault(); } return(office); }
public ActionResult Index(BasicForm.Models.DBRepresentations.Provider provider) { if (ModelState.IsValid) { using (CalendarEntities entities = new CalendarEntities()) { Provider prov = entities.Providers.Where(x => x.Email.Equals(provider.Email) && x.PassHashed.Equals(provider.PassHashed)).SingleOrDefault(); if (prov != null) { Session["LogedUserID"] = prov.ID.ToString(); return(RedirectToAction("Logged")); } } } return(RedirectToAction("Index", new { firstTry = false })); }
public static DateTime loadCalendar() { CalendarEntities db = new CalendarEntities(); List <DateTime> vista = db.vw_Listar_Fecha.Where(x => x.idEntidad_User == 1).Select(s => s.fecha).ToList(); // var calendar = sender as Calendar; /* for (int i = 00; i <= 59; i++) * {*/ //calendar.BlackoutDates.Add(new CalendarDateRange(new DateTime(2018, 2, 16))); // } /* * calendarWithBlackoutDates.BlackoutDates.Add( new CalendarDateRange(new DateTime(2009, 1, 16))); * */ return(vista[0]); }
public JsonResult DeleteEvent(int EventId) { var status = false; using (CalendarEntities calendar = new CalendarEntities()) { var events = calendar.Events.Where(e => e.EventId == EventId).FirstOrDefault(); if (events != null) { calendar.Events.Remove(events); calendar.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status } }); }
/// <summary> /// Page with info that you are logged /// </summary> /// <returns>Page with success text</returns> public ActionResult Logged() { if (Session["LogedUserID"] != null) { using (CalendarEntities entities = new CalendarEntities()) { int sessionID; bool succes = Int32.TryParse(Session["LogedUserID"].ToString(), out sessionID); if (succes) { Provider prov = entities.Providers.Where(x => x.ID.Equals(sessionID)).SingleOrDefault(); return(View(prov)); } } } return(RedirectToAction("Index")); }
/// <summary> /// takes day, mounth and year and return list of taken times in this day /// </summary> /// <param name="mounth">to be found in</param> /// <param name="year">to be found in</param> /// <param name="day">to be found in</param> /// <returns>Set of strings where strings are in format DD_HH:MM</returns> public static List <String> getTakenTimesByMonthYearDay(int officeID, int day, int month, int year) { List <string> _times = new List <string>(); using (CalendarEntities db = new CalendarEntities()) { //potencional request for cheange to faster the code.... //<Date, ID of procedure> of Office is specified month and year Dictionary <DateTime, int> _ordersInDate = (from p in db.Orders where (p.OfficeID.Equals(officeID) && p.Begin.Year.Equals(year) && p.Begin.Month.Equals(month) && p.Begin.Day.Equals(day)) select p).ToDictionary(p => p.Begin, p => p.ProcedureID); //<id of procedure, lasts> of Office with Active status Dictionary <int, int> proceduresActive = (from p in db.Procedures where (p.OfficeID.Equals(officeID) && p.Active == true) select p).ToDictionary(p => p.ID, p => p.Lasts); //to get faster adding in cycle System.Text.StringBuilder sb = new System.Text.StringBuilder(); //parsing DateTime and Lasts into string foreach (KeyValuePair <DateTime, int> order in _ordersInDate) { for (int i = 0; i < proceduresActive[order.Value] / 10; i++) { DateTime time; time = order.Key; time = time.AddMinutes(i); sb.Clear(); sb.Append(time.Day).Append("_").Append(time.Hour).Append(":").Append(time.Minute); _times.Add(sb.ToString()); } } } return(_times); }
public CalendarProvider(int providerID = 2) { //DBHandlerProvider hProvider = new DBHandlerProvider(); //provider = hProvider.getByID(providerID); //DBHandlerOffice hOffice = new DBHandlerOffice(); //offices = hOffice.getByProviderIDActive(2); //currentOffice = offices.Any() ? offices.ElementAt(0) : null; //using(CalendarEntities cal = new CalendarEntities()) //{ // Provider provider = cal.Providers.Where(x => x.ID.Equals(providerID)).Select(x => x).SingleOrDefault(); // /* (from prov in cal.Providers // where (prov.ID.Equals(providerID)) // select prov).SingleOrDefault();*/ //} using (CalendarEntities db = new CalendarEntities()) { //TADY KURVA JE POTREBA PREPSAT DVOJKA NA PROVIDERID provider = db.Providers.Where(x => x.ID.Equals(providerID)).SingleOrDefault(); offices = db.Offices.Where(x => x.ProviderID.Equals(provider.ID)).ToList(); currentOffice = offices.FirstOrDefault(); if (currentOffice == null) { Console.WriteLine("PICWWWWWWWEEEE"); } currentOffice = offices.FirstOrDefault(); orders = db.Orders.Include("Customer").Include("Procedure").Where(x => x.OfficeID.Equals(currentOffice.ID)).ToList(); } Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error()); // Elmah.ErrorLog. }
public AppointmentRepository() { _db = new CalendarEntities(); }
public CustomerRepository(CalendarEntities db) { _db = db; }
public CountryRepository(CalendarEntities db) { _db = db; }
public UserRepository(CalendarEntities db) { this._db = db; }
/// <summary> /// takes mounth and year and return list of taken times in this month /// </summary> /// <param name="mounth">to be found in</param> /// <param name="year">to be found in</param> /// <returns>Set of strings where strings are in format DD_HH:MM</returns> public static List <String> getTakenTimesByMonthYear(int officeID, int month, int year) { //old code - delete after proof that entity framework recreation works properly //DBHandlerProcedure hProcedure = new DBHandlerProcedure(); //List<string> formatedOrders = new List<string>(); //DateTime time; //StringBuilder sb = new StringBuilder(); //DBHandlerOrder hOrder = new DBHandlerOrder(); //UtilityProcedure uProcedure = new UtilityProcedure(); //Dictionary<int, BasicForm.Models.DBRepresentations.Procedure> proceduresDic = uProcedure.getProceduresAsDictionary(hProcedure.getByOfficeIDAll(officeID)); //List<BasicForm.Models.DBRepresentations.Order> ordersInDate = hOrder.getByOfficeIDInMonthYear(officeID, month, year); //try //{ // foreach (BasicForm.Models.DBRepresentations.Order order in ordersInDate) // { // for (int i = 0; i < proceduresDic[order.ProcedureID].Lasts; i = i + 10) // { // time = order.DateAndTime; // time = time.AddMinutes(i); // sb.Clear(); // sb.Append(time.Day).Append("_").Append(time.Hour).Append(":").Append(time.Minute); // formatedOrders.Add(sb.ToString()); // } // } //}catch(Exception e) //{ // ErrorSignal.FromCurrentContext().Raise(e); // Console.WriteLine(e.ToString()); //} //return formatedOrders; //entity framework List <string> _times = new List <string>(); using (CalendarEntities db = new CalendarEntities()) { //potencional request for cheange to faster the code.... //<Date, ID of procedure> of Office is specified month and year Dictionary <DateTime, int> _ordersInDate = (from p in db.Orders where (p.OfficeID.Equals(officeID) && p.Begin.Year.Equals(year) && p.Begin.Month.Equals(month)) select p).ToDictionary(p => p.Begin, p => p.ProcedureID); //<id of procedure, lasts> of Office with Active status Dictionary <int, int> proceduresActive = (from p in db.Procedures where (p.OfficeID.Equals(officeID) && p.Active == true) select p).ToDictionary(p => p.ID, p => p.Lasts); //to get faster adding in cycle System.Text.StringBuilder sb = new System.Text.StringBuilder(); //parsing DateTime and Lasts into string foreach (KeyValuePair <DateTime, int> order in _ordersInDate) { for (int i = 0; i < proceduresActive[order.Value] / 10; i++) { DateTime time; time = order.Key; time = time.AddMinutes(i); sb.Clear(); sb.Append(time.Day).Append("_").Append(time.Hour).Append(":").Append(time.Minute); _times.Add(sb.ToString()); } } } return(_times); }