public Message Delete(int id) { var res = new Message(); try { using (var context = new ModeloAula()) { var objschoolsubject = context.SCHOOL_SUBJECTS.AsQueryable().Where(x => x.ID == id).FirstOrDefault(); if (objschoolsubject != null) { objschoolsubject.STATUS_ITEM = false; objschoolsubject.MODIFICATION_DATE = DateTime.Now; } else { throw new Exception("* Materia escolar no existe, favor de veríficar"); } context.Entry(objschoolsubject).State = EntityState.Modified; context.SaveChanges(); res.status_item = true; res.details = "Borrado con éxito"; res.details = JsonConvert.SerializeObject(res, Formatting.None); } } catch (Exception ex) { res.details = String.Format("* Incidencia al borrar Materia Escolar detalles:{0}", ex.Message); } return(res); }
public Message Update(SchoolSubjectVM objSchoolSubject) { var res = new Message(); try { using (var context = new ModeloAula()) { var vobjSchoolSubject = context.SCHOOL_SUBJECTS.AsQueryable().Where(x => x.ID == objSchoolSubject.Id).SingleOrDefault(); if (vobjSchoolSubject != null) { vobjSchoolSubject.RATING_RECORD = objSchoolSubject.RatingRecord; vobjSchoolSubject.MODIFICATION_DATE = DateTime.Now; vobjSchoolSubject.MAKER = objSchoolSubject.MAKER; } else { throw new Exception("* Materia Escolar No existe"); } context.Entry(vobjSchoolSubject).State = EntityState.Modified; context.SaveChanges(); res.status_item = true; res.details = "* Se han realizado los cambios correctamente"; res.details = JsonConvert.SerializeObject(res, Formatting.None); } } catch (Exception ex) { res.details = String.Format("* Incidencia al modíficar información de la materia escolar detalles:{0}", ex.Message); } return(res); }
public Message Create(SchoolAttendaceVM objSAVM) { var res = new Message(); try { SCHOOL_ATTENDANCE viewModel = new SCHOOL_ATTENDANCE { ATTENDANCE_RECORD = objSAVM.AttendanceRecord, STATUS_ITEM = true, CREATE_DATE = DateTime.Now, ID_SCHOOL_SUBJECTS = objSAVM.IdSchoolSubject, MAKER = objSAVM.MAKER, MODIFICATION_DATE = DateTime.Now }; using (var context = new ModeloAula()) { var vRegister = context.SCHOOL_ATTENDANCE.AsQueryable().Where(x => x.ID_SCHOOL_SUBJECTS == objSAVM.IdSchoolSubject).SingleOrDefault(); if (vRegister != null) throw new Exception(string.Format("* Ya se encuentra asignado la asistencia ")); context.Entry(viewModel).State = EntityState.Added; context.SaveChanges(); objSAVM.Id = viewModel.ID; res.status_item = true; res.details = JsonConvert.SerializeObject(objSAVM, Formatting.None); } } catch (Exception ex) { res.status_item = false; res.details = String.Format("* Incidencia al crear Materia Escolar detalles:{0}", ex.Message); } return res; }
public Message Update(SchoolAttendaceVM objSchoolAttendance) { var res = new Message(); try { using (var context = new ModeloAula()) { var vobjSchoolAttendance = context.SCHOOL_ATTENDANCE.AsQueryable().Where(x => x.ID == objSchoolAttendance.Id).SingleOrDefault(); if (vobjSchoolAttendance != null) { vobjSchoolAttendance.ATTENDANCE_RECORD = objSchoolAttendance.AttendanceRecord; vobjSchoolAttendance.MODIFICATION_DATE = DateTime.Now; vobjSchoolAttendance.MAKER = objSchoolAttendance.MAKER; } else throw new Exception(string.Format("* Asistencia {0} No existe", objSchoolAttendance.Id)); context.Entry(vobjSchoolAttendance).State = EntityState.Modified; context.SaveChanges(); res.status_item = true; res.details = string.Format("* Se han realizado los cambios correctamente de la asistencia {0}", objSchoolAttendance.Id); res.details = JsonConvert.SerializeObject(res, Formatting.None); } } catch (Exception ex) { res.details = String.Format("* Incidencia al modíficar información de la materia escolar detalles:{0}", ex.Message); } return res; }
public Message Create(SchoolSubjectVM objSchoolSubject) { var res = new Message(); try { // Convert to object required Mapper.Initialize(cfg => cfg.CreateMap <SchoolSubjectVM, SCHOOL_SUBJECTS>().ForMember(x => x.ID_CAT_DET, y => y.MapFrom(c => c.IdCatDet)) .ForMember(x => x.RATING_RECORD, y => y.MapFrom(c => c.RatingRecord)) .ForMember(x => x.ID_STUDENT, y => y.MapFrom(c => c.IdStudent))); var viewModel = AutoMapper.Mapper.Map <SCHOOL_SUBJECTS>(objSchoolSubject); using (var context = new ModeloAula()) { // TODO validate if exist School Subject var vSchoolSubject = context.CATALOG_DETAILS.AsQueryable().Where(x => x.ID_CATALOG_DEFINITION == (int)CATALOG_TABLES.SCHOOL_SUBJECTS && x.ROW_ITEM == objSchoolSubject.IdCatDet).SingleOrDefault(); if (vSchoolSubject == null) { throw new Exception("* Debe elegir una materia escolar Hábil"); } // TODO validate if exist Student var vStudent = context.STUDENTs.AsQueryable().Where(x => x.ID == objSchoolSubject.IdStudent && x.STATUS_ITEM == true).SingleOrDefault(); if (vStudent == null) { throw new Exception("* Debe elegir un estudiante Hábil"); } // TODO validate if exist Register var vRegister = context.SCHOOL_SUBJECTS.AsQueryable().Where(x => x.ID_CAT_DET == objSchoolSubject.IdCatDet && x.ID_STUDENT == objSchoolSubject.IdStudent).SingleOrDefault(); if (vRegister != null) { throw new Exception(string.Format("* Ya se encuentra asignado {0} para {1}", vSchoolSubject.FIELD0, vStudent.NAME)); } context.Entry(viewModel).State = EntityState.Added; context.SaveChanges(); objSchoolSubject.Id = viewModel.ID; res.status_item = true; res.details = JsonConvert.SerializeObject(objSchoolSubject, Formatting.None); } } catch (Exception ex) { res.status_item = false; res.details = String.Format("* Incidencia al crear Materia Escolar detalles:{0}", ex.Message); } return(res); }
public Message Create(StudentVM student) { var res = new Message(); var email = new Email { To = new List <string> { student.Email }, typeEmail = TypeEmail.CREATE }; try { student.Token = "-1000"; //student.Status = true; Mapper.Initialize(cfg => cfg.CreateMap <StudentVM, STUDENT>()); var viewModel = AutoMapper.Mapper.Map <STUDENT>(student); viewModel.STATUS_ITEM = true; using (var context = new ModeloAula()) { if (!context.STUDENTs.Any(x => x.EMAIL == viewModel.EMAIL)) { Task.Run(() => email.SendAsync()); context.Entry(viewModel).State = EntityState.Added; context.SaveChanges(); student.ID = viewModel.ID; res.status_item = true; res.details = JsonConvert.SerializeObject(student, Formatting.None); } else { res.status_item = false; res.details = string.Format("* El usuario {0} ya existe", viewModel.EMAIL); } } } catch (Exception ex) { res.details = String.Format("* Incidencia al crear usuario detalles:{0}", ex.Message); } Task.WaitAll(); return(res); }
public Message Update(StudentVM student) { var res = new Message(); try { if (student.ID > 0) { using (var context = new ModeloAula()) { var objstudent = context.STUDENTs.AsQueryable().Where(x => x.ID == student.ID).FirstOrDefault(); if (objstudent != null) { objstudent.NAME = student.Name; objstudent.LASTNAME = student.LastName; objstudent.PWD = student.PWD; objstudent.EMAIL = student.Email; objstudent.STATUS_ITEM = student.Status; objstudent.MODIFICATION_DATE = DateTime.Now; student.Token = objstudent.TOKEN = HashCore.Token(); } context.Entry(objstudent).State = EntityState.Modified; context.SaveChanges(); res.status_item = true; res.details = JsonConvert.SerializeObject(student, Formatting.None); } } else { res.status_item = false; res.details = String.Format("* Incidencia veríficar id usuario"); } } catch (Exception ex) { res.details = String.Format("* Incidencia al crear usuario detalles:{0}", ex.Message); } return(res); }
public Message Delete(int id) { var res = new Message(); try { if (id > 0) { using (var context = new ModeloAula()) { var objstudent = context.STUDENTs.AsQueryable().Where(x => x.ID == id).FirstOrDefault(); if (objstudent != null) { objstudent.STATUS_ITEM = false; objstudent.MODIFICATION_DATE = DateTime.Now; } context.Entry(objstudent).State = EntityState.Modified; context.SaveChanges(); res.status_item = true; res.details = "Borrado con éxito"; res.details = JsonConvert.SerializeObject(res, Formatting.None); } } else { res.status_item = false; res.details = String.Format("* Incidencia veríficar id usuario"); } } catch (Exception ex) { res.details = String.Format("* Incidencia al borrar usuario detalles:{0}", ex.Message); } return(res); }