public ActionResult Edit(int id) { TreatmentEditItem treatmentItem = new TreatmentEditItem(); if (id != 0) { var treatment = Manager.GetById(id); if (treatment != null) { treatmentItem.Id = treatment.Id; treatmentItem.Name = treatment.Name; treatmentItem.Description = treatment.Description; treatmentItem.PictureUrl = treatment.PictureUrl; treatmentItem.Price = treatment.Price; treatmentItem.TreatmentCategoryId = treatment.TreatmentCategoryId; treatmentItem.IsActive = treatment.IsActive; treatmentItem.DurationId = treatment.DurationId.HasValue?(ETreatmentDuration)Enum.ToObject(typeof(ETreatmentDuration), treatment.DurationId.Value):ETreatmentDuration.Sixty; } } else { treatmentItem.DurationId = ETreatmentDuration.Sixty; } treatmentItem.TreatmentCategoryList = GetTreatmentCategoryList(); treatmentItem.HasBookings = Manager.HasBookings(id); return(View("TreatmentEditView", treatmentItem)); }
// GET: /Calendar/Events public async Task <ActionResult> GetEvents(string dateTime, int treatmentId, int clinicId) { DateTimeOffset selectedStart = Convert.ToDateTime(dateTime); DateTimeOffset selectedEnd = new DateTimeOffset(); DateTimeOffset?eventStart = new DateTimeOffset(); DateTimeOffset?eventEnd = new DateTimeOffset(); ViewBag.IsBookingUrl = false; Treatment treatment = new Treatment(); treatment = TreatmentManager.GetById(treatmentId); if (treatment.DurationId != null) { selectedEnd = selectedStart.AddMinutes((int)treatment.DurationId); } //checking for appointment blocks by selected time if (!blockManager.CheckForBlocks(selectedStart, clinicId, treatmentId)) { return(Json(new { StatusId = EEventStatus.Busy })); } try { var credential = await GetCredentialForApiAsync(clinicId); var initializer = new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Calendar MVC", }; var service = new CalendarService(initializer); // Fetch the list of calendars. var calendars = await service.CalendarList.List().ExecuteAsync(); var res = calendars.Items.First().TimeZone; // Define parameters of request. If you want to use another calendar, change "primary" to the calendar Id. You could find it in the calendars variable. EventsResource.ListRequest request = service.Events.List("primary"); request.TimeMin = selectedStart.Date; request.TimeMax = selectedStart.Date.AddDays(1); request.ShowDeleted = false; request.SingleEvents = true; request.MaxResults = 10; request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; // List events. Events events = request.Execute(); if (events.Items != null && events.Items.Count > 0) { foreach (var eventItem in events.Items) { eventStart = DateTimeOffset.Parse(eventItem.Start.DateTimeRaw, CultureInfo.InvariantCulture); eventEnd = DateTimeOffset.Parse(eventItem.End.DateTimeRaw, CultureInfo.InvariantCulture); if (selectedStart.DateTime >= eventStart.Value.DateTime && selectedStart.DateTime < eventEnd.Value.DateTime) { return(Json(new { StatusId = EEventStatus.Busy })); } if (selectedEnd.DateTime <= eventEnd.Value.DateTime && selectedEnd.DateTime > eventStart.Value.DateTime) { return(Json(new { StatusId = EEventStatus.Busy })); } } } else { return(Json(new { StatusId = EEventStatus.NoData })); } return(Json(new { StatusId = EEventStatus.Free })); } catch (Exception ex) { return(Json(new { StatusId = EEventStatus.Error })); } }