public bool Append(ulong pos, byte[] b) { EditParams e = new EditParams(pos, b); ChangeLog.Add(e); return(true); }
public ActionResult Crud(EditParams param, DataManager dataManager) { if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments { var asd = "asd"; } else if ((param.action == "batch" && param.changed != null) || param.action == "update") // this block of code will execute while updating the appointment { var asd = "asd"; } return(View()); }
public JsonResult Batch(EditParams param) { try { if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments { var value = param.action == "insert" ? param.value : param.added[0]; db.Configuration.ProxyCreationEnabled = false; //int intMax = db.ScheduleEvents.ToList().Count > 0 ? db.ScheduleEvents.ToList().Max(p => p.Id) : 1; DateTime startTime = Convert.ToDateTime(value.StartTime); DateTime endTime = Convert.ToDateTime(value.EndTime); var currentTimeZone = TimeZone.CurrentTimeZone; ScheduleEvent appoint = new ScheduleEvent() { SheduleID = value.SheduleID, //Id = intMax + 1, StartTime = startTime.ToUniversalTime(), EndTime = endTime.ToUniversalTime(), Subject = value.Subject, Location = value.Location, Description = value.Description, Owner = value.Owner, Priority = value.Priority, Recurrence = value.Recurrence, RecurrenceType = value.RecurrenceType, Reminder = value.Reminder, Categorize = value.Categorize, AllDay = value.AllDay, RecurrenceEndDate = value.RecurrenceEndDate != null?Convert.ToDateTime(value.RecurrenceEndDate).ToUniversalTime() : endTime.ToUniversalTime(), RecurrenceStartDate = value.RecurrenceStartDate != null?Convert.ToDateTime(value.RecurrenceStartDate).ToUniversalTime() : startTime.ToUniversalTime(), RecurrenceRule = value.RecurrenceRule, RecurrenceTypeCount = value.RecurrenceTypeCount, CustomStyle = value.CustomStyle, RemiderType = value.RemiderType, RemiderTypeCount = value.RemiderTypeCount, RemiderStartDate = value.RemiderStartDate, RemiderEndDate = value.RemiderEndDate, RemiderRule = value.RemiderRule, VenueCode = value.VenueCode, ParticipationInvitee = value.ParticipationInvitee, ParticipationAttendee = value.ParticipationAttendee, EventCategory = value.EventCategory, Organizer = value.Organizer, MeetingType = value.MeetingType, PublicHoliday = value.PublicHoliday, Added_By = new UserManagement().getCurrentuser(), //value.Added_By, Date_Added = DateTime.Now, //value.Date_Added, EventOccured = value.EventOccured, NoEventOccuredComment = value.NoEventOccuredComment, IsBlockAppointment = value.IsBlockAppointment, VenueList = value.VenueList, BlockForAll = value.BlockForAll, }; db.Configuration.ProxyCreationEnabled = false; db.ScheduleEvents.Add(appoint); db.SaveChanges(); } else if (param.action == "remove") // this block of code will execute while removing the appointment { ScheduleEvent app = db.ScheduleEvents.Where(c => c.SheduleID.ToString() == param.key).FirstOrDefault(); var myevent = app; if (app != null) { db.ScheduleEvents.Remove(app); } db.SaveChanges(); } else if ((param.action == "batch" && param.changed != null) || param.action == "update") // this block of code will execute while updating the appointment { var value = param.action == "update" ? param.value : param.changed[0]; //var filterData = db.ScheduleEvents.Where(c => c.Id == Convert.ToInt32(value.Id)); db.Configuration.ProxyCreationEnabled = false; var filterData = db.ScheduleEvents.Where(c => c.SheduleID == value.SheduleID); if (filterData.Count() > 0) { DateTime startTime = Convert.ToDateTime(value.StartTime); DateTime endTime = Convert.ToDateTime(value.EndTime); ScheduleEvent appoint = db.ScheduleEvents.Single(A => A.SheduleID == value.SheduleID); appoint.StartTime = startTime.ToUniversalTime(); appoint.EndTime = endTime.ToUniversalTime(); appoint.Subject = value.Subject; appoint.Location = value.Location; appoint.Description = value.Description; appoint.Owner = value.Owner; appoint.Priority = Convert.ToByte(value.Priority); appoint.Recurrence = Convert.ToBoolean(value.Recurrence); appoint.RecurrenceType = value.RecurrenceType; appoint.RecurrenceTypeCount = Convert.ToInt16(value.RecurrenceTypeCount); appoint.Reminder = value.Reminder; appoint.Categorize = value.Categorize; appoint.AllDay = value.AllDay; appoint.RecurrenceEndDate = value.RecurrenceEndDate != null?Convert.ToDateTime(value.RecurrenceEndDate).ToUniversalTime() : endTime.ToUniversalTime(); appoint.RecurrenceStartDate = value.RecurrenceStartDate != null?Convert.ToDateTime(value.RecurrenceStartDate).ToUniversalTime() : startTime.ToUniversalTime(); appoint.RecurrenceRule = value.RecurrenceRule; appoint.RecurrenceTypeCount = value.RecurrenceTypeCount; appoint.CustomStyle = value.CustomStyle; appoint.RemiderType = value.RemiderType; appoint.RemiderTypeCount = value.RemiderTypeCount; appoint.RemiderStartDate = value.RemiderStartDate; appoint.RemiderEndDate = value.RemiderEndDate; appoint.RemiderRule = value.RemiderRule; appoint.VenueCode = value.VenueCode; appoint.ParticipationInvitee = value.ParticipationInvitee; appoint.ParticipationAttendee = value.ParticipationAttendee; appoint.EventCategory = value.EventCategory; appoint.Organizer = value.Organizer; appoint.MeetingType = value.MeetingType; appoint.PublicHoliday = value.PublicHoliday; appoint.Added_By = new UserManagement().getCurrentuser(); appoint.Date_Added = DateTime.Now; appoint.EventOccured = value.EventOccured; appoint.NoEventOccuredComment = value.NoEventOccuredComment; appoint.IsBlockAppointment = value.IsBlockAppointment; appoint.VenueCode = value.VenueList; appoint.BlockForAll = value.BlockForAll; } db.SaveChanges(); } } catch (Exception ex) { throw ex;//new Exception ex.Message; } IEnumerable data = new mascisEntities().ScheduleEvents.ToList(); // nw.Appointment.Take(5); return(Json(data, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateData(EditParams param) { if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments { var value = (param.action == "insert") ? param.value : param.added[0]; int intMax = db.ScheduleEventDatas.ToList().Count > 0 ? db.ScheduleEventDatas.ToList().Max(p => p.Id) : 1; DateTime startTime = Convert.ToDateTime(value.StartTime); DateTime endTime = Convert.ToDateTime(value.EndTime); ScheduleEventData appointment = new ScheduleEventData() { Id = intMax + 1, StartTime = startTime.ToLocalTime(), EndTime = endTime.ToLocalTime(), Subject = value.Subject }; db.ScheduleEventDatas.InsertOnSubmit(appointment); db.SubmitChanges(); } if (param.action == "update" || (param.action == "batch" && param.changed != null)) // this block of code will execute while updating the appointment { var value = (param.action == "update") ? param.value : param.changed[0]; var filterData = db.ScheduleEventDatas.Where(c => c.Id == Convert.ToInt32(value.Id)); if (filterData.Count() > 0) { DateTime startTime = Convert.ToDateTime(value.StartTime); DateTime endTime = Convert.ToDateTime(value.EndTime); ScheduleEventData appointment = db.ScheduleEventDatas.Single(A => A.Id == Convert.ToInt32(value.Id)); appointment.StartTime = startTime.ToLocalTime(); appointment.EndTime = endTime.ToLocalTime(); appointment.Subject = value.Subject; } db.SubmitChanges(); } if (param.action == "remove" || (param.action == "batch" && param.deleted != null)) // this block of code will execute while removing the appointment { if (param.action == "remove") { int key = Convert.ToInt32(param.key); ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == key).FirstOrDefault(); if (appointment != null) { db.ScheduleEventDatas.DeleteOnSubmit(appointment); } } else { foreach (var apps in param.deleted) { ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == apps.Id).FirstOrDefault(); if (apps != null) { db.ScheduleEventDatas.DeleteOnSubmit(appointment); } } } db.SubmitChanges(); } var data = db.ScheduleEventDatas.ToList(); return(Json(data, JsonRequestBehavior.AllowGet)); }
public List <ScheduleData> Batch([FromBody] EditParams param) { if (param.action == "insert" || (param.action == "batch" && (param.added.Count > 0))) // this block of code will execute while inserting the appointments { ScheduleData appoint = new ScheduleData(); object result; if (param.action == "insert") { var value = param.value; foreach (var fieldName in value.GetType().GetProperties()) { var newName = fieldName.ToString().Split(null); if (newName[1] == "Id") { result = (_dbContext.ScheduleData.ToList().Count > 0 ? _dbContext.ScheduleData.ToList().Max(p => p.Id) : 1) + 1; } else if (newName[1] == "StartTime" || newName[1] == "EndTime") { result = Convert.ToDateTime(fieldName.GetValue(value)); } else { result = fieldName.GetValue(value); } fieldName.SetValue(appoint, result); } _dbContext.ScheduleData.Add(appoint); } else { foreach (var item in param.added.Select((x, i) => new { Value = x, Index = i })) { var value = item.Value; foreach (var fieldName in value.GetType().GetProperties()) { var newName = fieldName.ToString().Split(null); if (newName[1] == "Id") { result = (_dbContext.ScheduleData.ToList().Count > 0 ? _dbContext.ScheduleData.ToList().Max(p => p.Id) : 1) + 1 + item.Index; } else if (newName[1] == "StartTime" || newName[1] == "EndTime") { result = Convert.ToDateTime(fieldName.GetValue(value)); } else { result = fieldName.GetValue(value); } fieldName.SetValue(appoint, result); } _dbContext.ScheduleData.Add(appoint); } } _dbContext.SaveChanges(); } if ((param.action == "remove") || (param.action == "batch" && (param.deleted.Count > 0))) // this block of code will execute while removing the appointment { if (param.action == "remove") { ScheduleData app = _dbContext.ScheduleData.Where(c => c.Id == Convert.ToInt32(param.key)).FirstOrDefault(); if (app != null) { _dbContext.ScheduleData.Remove(app); } } else { foreach (var a in param.deleted) { var app = _dbContext.ScheduleData.ToList().Where(c => c.Id == Convert.ToInt32(a.Id)).FirstOrDefault(); if (app != null) { _dbContext.ScheduleData.Remove(app); } } } _dbContext.SaveChanges(); } if (param.action == "update" || (param.action == "batch" && (param.changed.Count > 0))) // this block of code will execute while updating the appointment { var value = param.action == "update" ? param.value : param.changed[0]; var filterData = _dbContext.ScheduleData.Where(c => c.Id == Convert.ToInt32(value.Id)); if (filterData.Count() > 0) { ScheduleData appoint = _dbContext.ScheduleData.Single(A => A.Id == Convert.ToInt32(value.Id)); appoint.StartTime = Convert.ToDateTime(value.StartTime); appoint.EndTime = Convert.ToDateTime(value.EndTime); appoint.Subject = value.Subject; appoint.Recurrence = value.Recurrence; appoint.AllDay = value.AllDay; appoint.RecurrenceRule = value.RecurrenceRule; appoint.RoomId = value.RoomId; appoint.OwnerId = value.OwnerId; } _dbContext.SaveChanges(); } List <ScheduleData> data = GetData().ToList();// _dbContext.ScheduleData.Take(500).ToList(); return(data); }
public List <ScheduleEvent> UpdateData([FromBody] EditParams param) { if (param.action == "insert" || (param.action == "batch" && param.added.Count > 0)) // this block of code will execute while inserting the appointments { int intMax = _context.ScheduleEvents.ToList().Count > 0 ? _context.ScheduleEvents.ToList().Max(p => p.Id) : 1; for (var i = 0; i < param.added.Count; i++) { var value = (param.action == "insert") ? param.value : param.added[i]; DateTime startTime = Convert.ToDateTime(value.StartTime); DateTime endTime = Convert.ToDateTime(value.EndTime); ScheduleEvent appointment = new ScheduleEvent() { StartTime = startTime, EndTime = endTime, Subject = value.Subject, IsAllDay = value.IsAllDay, StartTimezone = value.StartTimezone, EndTimezone = value.EndTimezone, RecurrenceRule = value.RecurrenceRule, RecurrenceID = value.RecurrenceID, RecurrenceException = value.RecurrenceException, Description = value.Description, CategoryId = value.CategoryId, ProjectId = value.ProjectId }; _context.ScheduleEvents.Add(appointment); _context.SaveChanges(); } } if (param.action == "update" || (param.action == "batch" && param.changed.Count > 0)) // this block of code will execute while removing the appointment { var value = (param.action == "update") ? param.value : param.changed[0]; var filterData = _context.ScheduleEvents.Where(c => c.Id == Convert.ToInt32(value.Id)); if (filterData.Count() > 0) { DateTime startTime = Convert.ToDateTime(value.StartTime); DateTime endTime = Convert.ToDateTime(value.EndTime); ScheduleEvent appointment = _context.ScheduleEvents.Single(A => A.Id == Convert.ToInt32(value.Id)); appointment.StartTime = startTime; appointment.EndTime = endTime; appointment.StartTimezone = value.StartTimezone; appointment.EndTimezone = value.EndTimezone; appointment.Subject = value.Subject; appointment.IsAllDay = value.IsAllDay; appointment.RecurrenceRule = value.RecurrenceRule; appointment.RecurrenceID = value.RecurrenceID; appointment.RecurrenceException = value.RecurrenceException; appointment.Description = value.Description; appointment.ProjectId = value.ProjectId; appointment.CategoryId = value.CategoryId; } _context.SaveChanges(); } if (param.action == "remove" || (param.action == "batch" && param.deleted.Count > 0)) // this block of code will execute while updating the appointment { if (param.action == "remove") { int key = Convert.ToInt32(param.key); ScheduleEvent appointment = _context.ScheduleEvents.Where(c => c.Id == key).FirstOrDefault(); if (appointment != null) { _context.ScheduleEvents.Remove(appointment); } } else { foreach (var apps in param.deleted) { ScheduleEvent appointment = _context.ScheduleEvents.Where(c => c.Id == apps.Id).FirstOrDefault(); if (apps != null) { _context.ScheduleEvents.Remove(appointment); } } } _context.SaveChanges(); } return(_context.ScheduleEvents.ToList()); }
public async Task <ActionResult> UpdateSchedule(EditParams param) { if (param.added != null) { foreach (var add in param.added) { var valid = await SaveScheduleValidation(add); if (valid != "") { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, valid)); } await InsertSchedule(add); } } if (param.changed != null) { foreach (var change in param.changed) { var valid = await SaveScheduleValidation(change); if (valid != "") { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, valid)); } var schedules = await _prepareService.GetInspectionSchedulesNonFilter(change.Id); await UpdateSchedule(schedules.FirstOrDefault(), change); } } if (param.deleted != null) { foreach (var delete in param.deleted) { await DeleteSchedule(delete.Id); } } if (param.value != null) { var valid = await SaveScheduleValidation(param.value); if (valid != "") { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, valid)); } var schedules = await _prepareService.GetInspectionSchedulesNonFilter(param.value.Id); if (!schedules.Any()) { await InsertSchedule(param.value); } else { await UpdateSchedule(schedules.FirstOrDefault(), param.value); } } if (param.action == "remove" || (param.key != null && param.value == null)) { await DeleteSchedule(Convert.ToInt32(param.key)); } var data = await GetSchedules(); return(Json(data, JsonRequestBehavior.AllowGet)); }
public async Task<JsonResult> UpdateData([FromBody] EditParams param) { if (param==null) { return Json(NotFound()); } if (param.action == "insert" || (param.action == "batch" && param.added.Count != 0)) { var value = (param.action == "insert") ? param.value : param.added[0]; var client = await _clientRepository.GetClientWithUserAsync(value.ClientUsername); var doctor = await _doctorRepository.GetDoctorWithUserAsync(value.DoctorId); var animal = await _animalRepository.GetAnimalWithUserAsync(value.AnimalId); var specialization = await _specializationRepository.GetByIdAsync(value.SpecializationId); Appointment appointment = new Appointment { Client = client, Animal = animal, Doctor = doctor, Specialization = specialization, Status = "Waiting", StartTime = value.StartTime, ClientDescription = value.ClientDescription }; await _appointmentRepository.CreateAsync(appointment); try { _mailHelper.SendMail(appointment.Client.User.UserName, "Appointment Requested", $"<h1>You have requested an appointment</h1>" + $"Please wait while we analyze your request!"); } catch (Exception) { } } if (param.action == "update" || (param.action == "batch" && param.changed.Count != 0)) { var value = param.changed[0]; var appointment = await _appointmentRepository.GetByIdWithModelsAsync(value.Id); if (appointment!=null) { appointment.Animal = await _animalRepository.GetAnimalWithUserAsync(value.AnimalId); appointment.Doctor = await _doctorRepository.GetDoctorWithUserAsync(value.DoctorId); appointment.Specialization = await _specializationRepository.GetByIdAsync(value.SpecializationId); appointment.ClientDescription = value.ClientDescription; await _appointmentRepository.UpdateAsync(appointment); try { _mailHelper.SendMail(appointment.Client.User.UserName, "Appointment Updated", $"<h1>Your Appointment request has been updated.</h1>" + $"Please wait while we analyze your request!"); } catch (Exception) { } } } if (param.action == "remove" || (param.action == "batch" && param.deleted.Count != 0)) { if (param.action == "remove") { } else { foreach (var apps in param.deleted) { var appointment = await _appointmentRepository.GetByIdWithModelsAsync(apps.Id); if (appointment!=null && appointment.Status=="Waiting") { await _appointmentRepository.DeleteAsync(appointment); try { _mailHelper.SendMail(appointment.Client.User.UserName, "Appointment Canceled", $"<h1>Your appointment request has been canceled!</h1>" + $"Your appointment for { appointment.Animal.Name} with the date { appointment.StartTime} has been canceled."); } catch (Exception) { } } } } } var data = _appointmentRepository.GetAllWithModels().ToList(); return Json(data, new Newtonsoft.Json.JsonSerializerSettings()); }