public JsonResult Save(Models.DTO.Schedule record) { Schedule entity; using (CBDBEntities context = new CBDBEntities()) { if (record.Id == 0) { entity = context.Schedules.First(p => p.Id == record.Id); entity.text = record.text; //entity.SchTypeId = record.SchTypeId; //entity.Country = context.Locations.FirstOrDefault(l => l.ID == record.CountryID); // entity.statusId = record.statusId; // entity.JobId = record.JobId; entity.start_date = record.start_date; entity.end_date = record.end_date; } else { context.Schedules.Add(new Schedule { Id = record.Id, text = record.text, //statusId = record.statusId, // JobId = record.JobId, // SchTypeId = record.SchTypeId, start_date = record.start_date, end_date = record.end_date, }); } context.SaveChanges(); } return(Json(new { result = true })); }
// GET: EmployeesGrouping public JsonResult Get(string groupBy, string groupByDirection, int?page, int?limit) { List <Models.DTO.Employee> records; int total; using (CBDBEntities context = new CBDBEntities()) { var query = context.Employees.Select(p => new Models.DTO.Employee { Id = p.Id, firstName = p.firstName, mobile = p.mobile, email = p.email, countyId = p.countyId, bared = p.bared, // CountyName = p.County != null ? p.County.Name : "", // bared = p.bared != null ? p.bared : "", IsAvailable = p.IsAvailable, startDate = p.startDate, note = p.note, photo = p.photo, nextOfKin = p.nextOfKin, alergy = p.alergy, postNominals = p.postNominals, }); if (groupBy == "County") { if (groupByDirection.Trim().ToLower() == "asc") { query = query.OrderBy(q => q.countyId); } else { query = query.OrderByDescending(q => q.countyId); } } //else //{ // query = query.OrderBy(q => q.OrderNumber); //} total = query.Count(); if (page.HasValue && limit.HasValue) { int start = (page.Value - 1) * limit.Value; records = query.Skip(start).Take(limit.Value).ToList(); } else { records = query.ToList(); } } return(this.Json(new { records, total }, JsonRequestBehavior.AllowGet)); }
public JsonResult Delete(int id) { using (CBDBEntities context = new CBDBEntities()) { Schedule entity = context.Schedules.First(p => p.Id == id); context.Schedules.Remove(entity); context.SaveChanges(); } return(Json(new { result = true })); }
// GET: SchedulesGrouping public JsonResult Get(string groupBy, string groupByDirection, int?page, int?limit) { List <Models.DTO.Job> records; int total; using (CBDBEntities context = new CBDBEntities()) { var query = context.Jobs.Select(p => new Models.DTO.Job { Id = p.Id, text = p.text, Description = p.Description, Location = p.Location, start_date = p.start_date, DateCreated = p.DateCreated, end_date = p.end_date, TXDate = p.TXDate, Coordinator = p.Coordinator, CommercialLead = p.CommercialLead, ClientId = p.ClientId //ClientName = p.Client.Name, //CountryName = p.Country != null ? p.Country.Name : "", //statusId = p.statusId }); if (groupBy == "ClientId") { if (groupByDirection.Trim().ToLower() == "asc") { query = query.OrderBy(q => q.ClientId);/*.ThenBy(q => q.OrderNumber);*/ } else { query = query.OrderByDescending(q => q.ClientId);/*.ThenBy(q => q.OrderNumber);*/ } } //else //{ // query = query.OrderBy(q => q.OrderNumber); //} total = query.Count(); if (page.HasValue && limit.HasValue) { int start = (page.Value - 1) * limit.Value; records = query.Skip(start).Take(limit.Value).ToList(); } else { records = query.ToList(); } } return(this.Json(new { records, total }, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(Models.DTO.Employee record) { Employee entity; using (CBDBEntities context = new CBDBEntities()) { if (record.Id > 0) { entity = context.Employees.First(p => p.Id == record.Id); entity.firstName = record.firstName; entity.mobile = record.mobile; entity.note = record.note; entity.countyId = record.countyId; entity.email = record.email; entity.bared = record.bared; entity.startDate = record.startDate; //entity.countyId = record.countyId; //entity.email = record.email; // entity.Country = context.Locations.FirstOrDefault(l => l.ID == record.CountryID); entity.IsAvailable = record.IsAvailable; entity.photo = record.photo; entity.nextOfKin = record.nextOfKin; entity.alergy = record.alergy; entity.postNominals = record.postNominals; } else { context.Employees.Add(new Employee { firstName = record.firstName, email = record.email, countyId = record.countyId, mobile = record.mobile, note = record.note, bared = record.bared, startDate = record.startDate, // Has_Role = context.Roles.FirstOrDefault(l => l.Id == record.Id), IsAvailable = record.IsAvailable, photo = record.photo, nextOfKin = record.nextOfKin, alergy = record.alergy, postNominals = record.postNominals }); } context.SaveChanges(); } return(Json(new { result = true })); }
//START SECOND //public List<Models.DTO.Schedule> GetSchedule(string jobid, int scheduleid) public Models.DTO.Schedule GetSchedule(string jobid, int scheduleid) { if (jobid != string.Empty) { using (var context = new CBDBEntities()) { var schedule = context.Schedules.AsNoTracking() .Where(x => x.JobId == jobid && x.Id == scheduleid) .Single(); if (schedule != null) { var scheduleVm = new Models.DTO.Schedule() { JobId = schedule.JobId, text = schedule.text?.Trim(), start_date = schedule.start_date, end_date = schedule.end_date, }; //var schTypesRepo = new SchTypeRepository(); //scheduleVm.SchTypName = schTypesRepo.GetSchTypeName(schedule.SchTypeId); //var jobStatuRepo = new JobStatuRepository(); //scheduleVm.StatusName = jobStatuRepo.GetJobStatuName(schedule.statusId); var schTypesRepo = new SchTypeRepository(); scheduleVm.SchTypName = schTypesRepo.GetSchTypes().ToString(); var schStatuRepo = new ScheduleStatuRepository(); //scheduleVm.StatusName = schStatuRepo.GetScheduleStatus().ToString(); //var schTypesRepo = new SchTypeRepository(); //scheduleVm.SchTypName = schTypesRepo.GetSchTypes().ToString(); //var scheduleStatuRepo = new ScheduleStatuRepository(); //scheduleVm.StatusName = scheduleStatuRepo.GetScheduleStatus().ToString(); return(scheduleVm); } } } return(null); }
// START SCHEDULE LIST // public List<Models.DTO.ScheduleListView> GetScheduleList(string jobid) public Models.DTO.ScheduleListView GetScheduleList(string jobid) { if (jobid != string.Empty) { using (var context = new CBDBEntities()) { var schedules = context.Schedules.AsNoTracking() .Where(x => x.JobId == jobid) .OrderBy(x => x.Id); if (schedules != null) { var scheduleListView = new ScheduleListView(); foreach (var schedule in schedules) { var scheduleVm = new Models.DTO.Schedule() { JobId = schedule.JobId.ToString(), Id = schedule.Id, text = schedule.text, //SchTypeId = schedule.SchTypeId, //SchTypName = schedule.SchType.name, start_date = schedule.start_date, end_date = schedule.end_date, //StatusName = schedule.ScheduleStatu.title }; //var schTypesRepo = new SchTypeRepository(); //scheduleVm.SchTypName = schTypesRepo.GetSchTypeName(schedule.SchTypeId); //var jobStatuRepo = new JobStatuRepository(); //scheduleVm.StatusName = jobStatuRepo.GetJobStatuName(schedule.statusId); //scheduleListView.Schedules.Add(scheduleVm); var schTypesRepo = new SchTypeRepository(); scheduleVm.SchTypName = schTypesRepo.GetSchTypes().ToString(); var schStatuRepo = new ScheduleStatuRepository(); //scheduleVm.StatusName = schStatuRepo.GetScheduleStatus().ToString(); scheduleListView.Schedules.Add(scheduleVm); } return(scheduleListView); } } } return(null); }
public JsonResult Save(Models.DTO.Job record) { Job entity; using (CBDBEntities context = new CBDBEntities()) { if (record.Id.Length == 0) { entity = context.Jobs.First(p => p.Id == record.Id); entity.text = record.text; entity.Description = record.Description; entity.Location = record.Location; entity.ClientId = record.ClientId; //entity.Country = context.Locations.FirstOrDefault(l => l.ID == record.CountryID); // entity.statusId = record.statusId; entity.DateCreated = record.DateCreated; entity.TXDate = record.TXDate; entity.start_date = record.start_date; entity.end_date = record.end_date; entity.Coordinator = record.Coordinator; entity.CommercialLead = record.CommercialLead; } else { context.Jobs.Add(new Job { Id = record.Id, text = record.text, Description = record.Description, Location = record.Location, start_date = record.start_date, DateCreated = record.DateCreated, end_date = record.end_date, TXDate = record.TXDate, Coordinator = record.Coordinator, CommercialLead = record.CommercialLead, ClientId = record.ClientId, // statusId = record.statusId, }); } context.SaveChanges(); } return(Json(new { result = true })); }
public ScheduleEdit SaveSchedule(ScheduleEdit model) { //if (model != null && string.IsNullOrEmpty(model.JobId) ) if (model != null && Guid.TryParse(model.Id.ToString(), out Guid jobid)) { using (var context = new CBDBEntities()) { //if (string.IsNullOrEmpty(jobedit.Id)) //{ var schedule = new Models.Schedule() { //Id = newGuid.ToString(), //Id = customerid, // JobId = model.JobId, JobId = jobid.ToString(), text = model.text, start_date = model.start_date, end_date = model.end_date, //statusId = model.SelectedStatus, SchTypeId = model.SelectedSchType }; schedule.SchType = context.SchTypes.Find(schedule.SchTypeId); //schedule.ScheduleStatu = context.ScheduleStatus.Find(schedule.statusId); context.Schedules.Add(schedule); context.SaveChanges(); var schTypesRepo = new SchTypeRepository(); model.SchType = schTypesRepo.GetSchTypes(); var schStatuRepo = new ScheduleStatuRepository(); //model.ScheduleStatu = schStatuRepo.GetScheduleStatus(); return(model); } } // Return false if customeredit == null or CustomerID is not a guid return(null); }
public JobEdit GetJob(string id) { if (id != string.Empty) { using (var context = new CBDBEntities()) { var job = context.Jobs.AsNoTracking() .Where(j => j.Id == id) .Single(); if (job != null) { var jobEditVm = new JobEdit() { Id = job.Id /*.ToString("")*/, text = job.text.Trim(), Description = job.Description, //NameConcatenateLocation = j. DateCreated = job.DateCreated, Location = job.Location, Coordinator = job.Coordinator, // ClientName = j.Client.Name, start_date = job.start_date, TXDate = job.TXDate, end_date = job.end_date, CommercialLead = job.CommercialLead, SelectedClient = job.Client.Id, //SelectedStatus = job.JobStatu.Id }; var clientsRepo = new ClientRepository(); jobEditVm.Client = clientsRepo.GetClients(); //var jobStatuRepo = new JobStatuRepository(); //jobEditVm.JobStatu = jobStatuRepo.GetJobStatus(); return(jobEditVm); } } } return(null); }
public bool SaveJob(JobEdit jobedit) { if (jobedit != null) { using (var context = new CBDBEntities()) { // if (string.IsNullOrEmpty(jobedit.Id)) if (Guid.TryParse(jobedit.Id, out Guid newGuid)) { var job = new Models.Job() { Id = newGuid.ToString(), // Id = ToString(), text = jobedit.text, Description = jobedit.Description, Location = jobedit.Location, Coordinator = jobedit.Coordinator, DateCreated = jobedit.DateCreated, //NameConcatenateLocation = jobEdit.Name, start_date = jobedit.start_date, TXDate = jobedit.TXDate, end_date = jobedit.end_date, ClientId = jobedit.SelectedClient, // statusId = jobedit.SelectedStatus, CommercialLead = jobedit.CommercialLead }; job.Client = context.Clients.Find(jobedit.SelectedClient); //job.JobStatu = context.JobStatus.Find(jobedit.SelectedStatus); context.Jobs.Add(job); context.SaveChanges(); return(true); } } } // Return false if customeredit == null or CustomerID is not a guid return(false); }
public List <Models.DTO.Job> GetJobs() { using (var context = new CBDBEntities()) { List <Models.Job> jobs = new List <Models.Job>(); jobs = context.Jobs.AsNoTracking() // .Include(j => j.Client) .ToList(); if (jobs != null) { List <Models.DTO.Job> jobsDisplay = new List <Models.DTO.Job>(); foreach (var j in jobs) { var jobDisplay = new Models.DTO.Job() { Id = j.Id, text = j.text, //NameConcatenateLocation = j. DateCreated = j.DateCreated, Location = j.Location, Coordinator = j.Coordinator, // ClientId = j.Client.Name, ClientId = j.ClientId, start_date = j.start_date, TXDate = j.TXDate, end_date = j.end_date, CommercialLead = j.CommercialLead // Status = j.Status }; jobsDisplay.Add(jobDisplay); } return(jobsDisplay); } return(null); } }
public IEnumerable <SelectListItem> GetSchTypes() { using (var context = new CBDBEntities()) { List <SelectListItem> schtype = context.SchTypes.AsNoTracking() .OrderBy(cl => cl.name) .Select(cl => new SelectListItem { Value = cl.Id.ToString(), Text = cl.name } ).ToList(); var schtypestip = new SelectListItem() { Value = null, Text = "---select type---" }; schtype.Insert(0, schtypestip); return(new SelectList(schtype, "Value", "Text")); } }
public IEnumerable <SelectListItem> GetRoles() { using (var context = new CBDBEntities()) { List <SelectListItem> roles = context.Roles.AsNoTracking() .OrderBy(cl => cl.Name) .Select(cl => new SelectListItem { Value = cl.Id.ToString(), Text = cl.Name } ).ToList(); var rolestip = new SelectListItem() { Value = null, Text = "---select role---" }; roles.Insert(0, rolestip); return(new SelectList(roles, "Value", "Text")); } }
public IEnumerable <SelectListItem> GetClients() { using (var context = new CBDBEntities()) { List <SelectListItem> clients = context.Clients.AsNoTracking() .OrderBy(cl => cl.Name) .Select(cl => new SelectListItem { Value = cl.Id.ToString(), Text = cl.Name } ).ToList(); var clienttip = new SelectListItem() { Value = null, Text = "---select client---" }; clients.Insert(0, clienttip); return(new SelectList(clients, "Value", "Text")); } }
public JsonResult GetSchedules(string Id, int?page, int?limit) { List <Models.DTO.Schedule> records; int total; using (CBDBEntities context = new CBDBEntities()) { var query = context.Schedules.Where(pt => pt.JobId == Id).Select(pt => new Models.DTO.Schedule { Id = pt.Id, //JobId = pt.JobId, //JobName = pt. text = pt.text, // SchTypeId = pt.SchTypeId, SchTypName = pt.SchType.name, start_date = pt.start_date, end_date = pt.end_date, //statusId = pt.statusId, //StatusName = pt.ScheduleStatu.title }); total = query.Count(); if (page.HasValue && limit.HasValue) { int start = (page.Value - 1) * limit.Value; records = query.OrderBy(pt => pt.start_date).Skip(start).Take(limit.Value).ToList(); } else { records = query.ToList(); } } return(this.Json(new { records, total }, JsonRequestBehavior.AllowGet)); }
// GET: SchedRoles public JsonResult Get(int?page, int?limit, string sortBy, string direction, string schedname) { List <Models.DTO.Schedule> records; int total; using (CBDBEntities context = new CBDBEntities()) { var query = context.Schedules.Select(p => new Models.DTO.Schedule { Id = p.Id, text = p.text, start_date = p.start_date, end_date = p.end_date, SchTypName = p.SchType.name, //jo = p.Client.Name, // statusId = p.statusId, //StatusName = p.ScheduleStatu.title }); if (!string.IsNullOrWhiteSpace(schedname)) { query = query.Where(q => q.text.Contains(schedname)); } if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction)) { if (direction.Trim().ToLower() == "asc") { switch (sortBy.Trim().ToLower()) { case "schedname": query = query.OrderBy(q => q.text); break; } } else { switch (sortBy.Trim().ToLower()) { case "schedname": query = query.OrderByDescending(q => q.text); break; } } } else { query = query.OrderBy(q => q.start_date); } total = query.Count(); if (page.HasValue && limit.HasValue) { int start = (page.Value - 1) * limit.Value; records = query.Skip(start).Take(limit.Value).ToList(); } else { records = query.ToList(); } } return(this.Json(new { records, total }, JsonRequestBehavior.AllowGet)); }
// GET: Employees public JsonResult Get(int?page, int?limit, string sortBy, string direction, string firstname, string bare) { List <Models.DTO.Employee> records; int total; using (CBDBEntities context = new CBDBEntities()) { var query = context.Employees.Select(p => new Models.DTO.Employee { Id = p.Id, firstName = p.firstName, mobile = p.mobile, email = p.email, countyId = p.countyId, // bared = p.bared, // CountyName = p.County != null ? p.County.Name : "", bared = p.bared != null ? p.bared : "", IsAvailable = p.IsAvailable, startDate = p.startDate, note = p.note, photo = p.photo, nextOfKin = p.nextOfKin, alergy = p.alergy, postNominals = p.postNominals, // OrderNumber = p.OrderNumber }); if (!string.IsNullOrWhiteSpace(firstname)) { query = query.Where(q => q.firstName.Contains(firstname)); } if (!string.IsNullOrWhiteSpace(bare)) { query = query.Where(q => q.bared.Contains(bare)); } //if (!string.IsNullOrWhiteSpace(lastname)) //{ // query = query.Where(q => q.lastName != null && q.lastName.Contains(lastname)); //} //if (!string.IsNullOrWhiteSpace(bare)) //{ // query = query.Where(q => q.bared != null && q.bared.Contains("a")); //} //if (!string.IsNullOrWhiteSpace(lastname)) //{ // query = query.Where(q => q.lastName.Contains(lastname)); //} if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction)) { if (direction.Trim().ToLower() == "asc") { switch (sortBy.Trim().ToLower()) { case "fullname": query = query.OrderBy(q => q.firstName); break; case "bare": query = query.OrderBy(q => q.bared); break; //case "dateofbirth": // query = query.OrderBy(q => q.DateOfBirth); // break; } } else { switch (sortBy.Trim().ToLower()) { case "fullname": query = query.OrderByDescending(q => q.firstName); break; case "bare": query = query.OrderByDescending(q => q.bared); break; //case "dateofbirth": // query = query.OrderByDescending(q => q.DateOfBirth); // break; } } } //else //{ // query = query.OrderBy(q => q.OrderNumber); //} total = query.Count(); if (page.HasValue && limit.HasValue) { int start = (page.Value - 1) * limit.Value; records = query.Skip(start).Take(limit.Value).ToList(); } else { records = query.ToList(); } } return(this.Json(new { records, total }, JsonRequestBehavior.AllowGet)); }