public ActionResult deleteUser(string id) { DBEnt db = new DBEnt(); var user = db.AspNetUsers.Where(x => x.Id == id).FirstOrDefault(); List <AspNetRole> roles = user.AspNetRoles.ToList(); try { if (roles.FirstOrDefault().Name == "Admin") { return(Content("Admin cannot be deleted!")); } if (roles.FirstOrDefault().Name != "Admin") { db.Entry(user).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Alerts.deleteUser = true; return(RedirectToAction("allUsers", "Admin")); } } catch { db.Entry(user).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Alerts.deleteUser = true; return(RedirectToAction("allUsers", "Admin")); } return(Content("Error........")); }
public ActionResult addExam(ExamViewModel collection) { List <ExamSubject> sublist = new List <ExamSubject>(); foreach (long i in collection.Subjects) { ExamSubject obj = new ExamSubject() { SubjectId = i, }; if (!sublist.Contains(obj)) { sublist.Add(obj); } } if (!examExist(collection.Name)) { DBEnt db = new DBEnt(); string filename = Path.GetFileNameWithoutExtension(collection.Image.FileName); string ext = Path.GetExtension(collection.Image.FileName); filename = filename + DateTime.Now.Millisecond.ToString(); filename = filename + ext; string filetodb = "/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image/"), filename); collection.Image.SaveAs(filename); collection.Cover = filetodb; Exam exm = new Exam() { Name = collection.Name, Cover = collection.Cover, MarkPerMcq = collection.MarkPerMcq, NegativeMark = collection.NegativeMark, TimeInMinutes = collection.TimeInMinutes }; db.Exams.Add(exm); db.SaveChanges(); foreach (ExamSubject i in sublist) { i.ExamId = exm.Id; db.ExamSubjects.Add(i); } db.SaveChanges(); Alerts.addExam = true; return(RedirectToAction("addExam", "Admin")); } else { Alerts.alreadyExist = true; return(RedirectToAction("addExam", "Admin")); } }
public ActionResult addSubject(SubjectViewModel collection) { if (!subjectExist(collection.Name)) { DBEnt db = new DBEnt(); string filename = Path.GetFileNameWithoutExtension(collection.Image.FileName); string ext = Path.GetExtension(collection.Image.FileName); filename = filename + DateTime.Now.Millisecond.ToString(); filename = filename + ext; string filetodb = "/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image/"), filename); collection.Image.SaveAs(filename); collection.Cover = filetodb; db.Subjects.Add(new Subject() { Name = collection.Name, Cover = collection.Cover }); db.SaveChanges(); Alerts.addSubject = true; return(RedirectToAction("addSubject", "Admin")); } else { Alerts.alreadyExist = true; return(RedirectToAction("addSubject", "Admin")); } }
public ActionResult AddMcq(McqViewModel collection) { //return Json(collection, JsonRequestBehavior.AllowGet); Mcq mcq = new Mcq() { ExamId = collection.ExamId, SubjectId = collection.SubjectId, ChapterId = collection.ChapterId, Question = collection.Question.ToString(), OptionA = collection.OptionA.ToString(), OptionB = collection.OptionB.ToString(), OptionC = collection.OptionC.ToString(), OptionD = collection.OptionD.ToString(), CorrectOption = collection.CorrectOption.ToString(), UpVotes = 5, DownVotes = 0, Status = "approve", EntryDate = DateTime.Now, }; DBEnt db = new DBEnt(); db.Submissions.Add(new Submission() { UserID = User.Identity.GetUserId(), McqId = mcq.Id }); db.Mcqs.Add(mcq); db.SaveChanges(); Alerts.addMcq = true; return(RedirectToAction("allMcq", "Admin")); }
public ActionResult InsertInteres(string id_user, string interes, int id_producto, string name) { using (DBEnt db = new DBEnt()) { DateTime aDate = DateTime.Now; var interestr = interes; interestr = interestr.Replace("%", ""); var intereDeci = Convert.ToDecimal(interestr); var interx = new ProductoFinancieroInteres() { id_productofinanciero = id_producto, interes = intereDeci }; db.ProductoFinancieroInteres.Add(interx); db.SaveChanges(); } var action = "Insert"; var comments = "Interes para Producto Financiero " + name + " ingresado por el usuario : "; InsertInBitacora(id_user, action, comments + id_user); return(RedirectToAction("Details", "ProductoFinanciero", new { id = id_producto })); }
//Open Source Submission public ActionResult addOpenSpurceMcq(McqViewModel collection) { Mcq mcq = new Mcq() { ExamId = collection.ExamId, SubjectId = collection.SubjectId, ChapterId = collection.ChapterId, Question = collection.Question, OptionA = collection.OptionA, OptionB = collection.OptionB, OptionC = collection.OptionC, OptionD = collection.OptionD, CorrectOption = collection.CorrectOption, UpVotes = 5, DownVotes = 0, Status = "pending", EntryDate = DateTime.Now, }; string userId = User.Identity.GetUserId().ToString(); DBEnt db = new DBEnt(); db.Mcqs.Add(mcq); db.Submissions.Add(new Submission() { UserID = User.Identity.GetUserId(), McqId = mcq.Id }); db.SaveChanges(); Alerts.openSubmit = true; return(RedirectToAction("Index", "Front")); }
public ActionResult deleteChapter(int?id) { DBEnt db = new DBEnt(); List <Mcq> mcq = db.Mcqs.Where(x => x.ChapterId == id).ToList <Mcq>(); foreach (Mcq i in mcq) { db.Entry(i).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); Chapter chapter = db.Chapters.Where(x => x.Id == id).First(); db.Entry(chapter).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Alerts.deleteChapter = true; return(RedirectToAction("addChapter", "Admin")); }
public ActionResult disapproveMcq(int?id) { DBEnt db = new DBEnt(); var mcq = db.Mcqs.Where(x => x.Id == id).First(); mcq.Status = "pending"; db.SaveChanges(); Alerts.disapprove = true; return(RedirectToAction("allMcq", "Admin")); }
public ActionResult deleteMcq(int id) { DBEnt db = new DBEnt(); List <Submission> submissions = db.Submissions.Where(x => x.McqId == id).ToList <Submission>(); foreach (Submission i in submissions) { db.Entry(i).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); Mcq mcq = db.Mcqs.Where(x => x.Id == id).First(); db.Entry(mcq).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Alerts.deleteMcq = true; return(RedirectToAction("allMcq", "Admin")); }
public ActionResult deleteMessage(int?id) { DBEnt db = new DBEnt(); var message = db.Messages.Where(x => x.Id == id).First(); db.Entry(message).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Alerts.deleteMessage = true; return(RedirectToAction("viewMessagaes", "Admin")); }
public ActionResult deleteExam(int?id) { DBEnt db = new DBEnt(); var mcqs = db.Mcqs.Where(x => x.ExamId == id).ToList <Mcq>(); foreach (var i in mcqs) { db.Entry(i).State = System.Data.Entity.EntityState.Deleted; var sub = db.Submissions.Where(x => x.McqId == i.Id).FirstOrDefault(); db.Entry(sub).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); var exam = db.Exams.Where(x => x.Id == id).First(); db.Entry(exam).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Alerts.deleteExam = true; return(RedirectToAction("AddExam", "Admin")); }
public ActionResult editChapter(long?id, ChapterViewModel collection) { DBEnt db = new DBEnt(); var chap = db.Chapters.Where(x => x.Id == id).FirstOrDefault(); chap.Name = collection.Name; chap.ChapterNo = collection.ChapterNo; db.SaveChanges(); Alerts.chapterupdated = true; return(RedirectToAction("addChapter", "Admin")); }
public ActionResult addChapter(ChapterViewModel collection) { DBEnt db = new DBEnt(); Chapter chapter = new Chapter() { SubjectId = collection.SubjectId, Name = collection.Name, ChapterNo = collection.ChapterNo }; db.Chapters.Add(chapter); db.SaveChanges(); Alerts.addChapter = true; return(RedirectToAction("addChapter", "Admin")); }
public ActionResult editMcq(long id, McqViewModel collection) { DBEnt db = new DBEnt(); var mcq = db.Mcqs.Where(x => x.Id == id).FirstOrDefault(); mcq.Question = collection.Question; mcq.OptionA = collection.OptionA; mcq.OptionB = collection.OptionB; mcq.OptionC = collection.OptionC; mcq.OptionD = collection.OptionD; mcq.CorrectOption = collection.CorrectOption; db.SaveChanges(); Alerts.mcqupdated = true; return(RedirectToAction("allMcq", "Admin")); }
public ActionResult sendMessage(MessageViewModel collection) { DBEnt db = new DBEnt(); Message msg = new Message() { Subject = collection.Subject, Message1 = collection.Message, Date = DateTime.Now, Status = "unread", UserID = User.Identity.GetUserId() }; Alerts.messageSent = true; db.Messages.Add(msg); db.SaveChanges(); return(RedirectToAction("Index", "Front")); }
public void InsertInBitacora(string id_user, string action, string coments) { using (DBEnt db = new DBEnt()) { DateTime aDate = DateTime.Now; var bitacoraitem = new AdminBitacora() { id_userCreated = id_user, action = action, comments = coments, created_at = aDate, id = RandomNumber(1, 1000000000) }; db.AdminBitacora.Add(bitacoraitem); db.SaveChanges(); } }
public ActionResult deleteSubject(int?id) { DBEnt db = new DBEnt(); Subject subject = db.Subjects.Where(x => x.Id == id).First(); List <Mcq> mcq = db.Mcqs.Where(x => x.SubjectId == subject.Id).ToList <Mcq>(); foreach (Mcq i in mcq) { db.Entry(i).State = System.Data.Entity.EntityState.Deleted; } List <Chapter> chapters = db.Chapters.Where(x => x.SubjectId == subject.Id).ToList <Chapter>(); foreach (Chapter i in chapters) { db.Entry(i).State = System.Data.Entity.EntityState.Deleted; } db.Entry(subject).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Alerts.deleteSubject = true; return(RedirectToAction("addSubject", "Admin")); }
public ActionResult editSubject(long?id, SubjectViewModel collection) { DBEnt db = new DBEnt(); var subject = db.Subjects.Where(x => x.Id == id).FirstOrDefault(); if (collection.Image != null) { if (!subjectExist(collection.Name)) { string filename = Path.GetFileNameWithoutExtension(collection.Image.FileName); string ext = Path.GetExtension(collection.Image.FileName); filename = filename + DateTime.Now.Millisecond.ToString(); filename = filename + ext; string filetodb = "/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image/"), filename); collection.Image.SaveAs(filename); collection.Cover = filetodb; subject.Name = collection.Name; subject.Cover = collection.Cover; db.SaveChanges(); Alerts.subjectupdated = true; return(RedirectToAction("addSubject", "Admin")); } else { if (collection.Image != null) { string filename = Path.GetFileNameWithoutExtension(collection.Image.FileName); string ext = Path.GetExtension(collection.Image.FileName); filename = filename + DateTime.Now.Millisecond.ToString(); filename = filename + ext; string filetodb = "/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image/"), filename); collection.Image.SaveAs(filename); collection.Cover = filetodb; subject.Cover = collection.Cover; db.SaveChanges(); Alerts.subjectupdated = true; return(RedirectToAction("addSubject", "Admin")); } Alerts.alreadyExist = true; return(RedirectToAction("addSubject", "Admin")); } } else { if (!subjectExist(collection.Name)) { subject.Name = collection.Name; db.SaveChanges(); Alerts.subjectupdated = true; return(RedirectToAction("addSubject", "Admin")); } else { Alerts.alreadyExist = true; return(RedirectToAction("addSubject", "Admin")); } } return(View()); }
public ActionResult UpdateProductoFinanciero(EditProductoFin data) { var fx = data.files; if (fx == null) { using (DBEnt db = new DBEnt()) { var credito = db.HomeProductosFinancieros.ToList <HomeProductosFinancieros>().Where(u => u.id.Equals(data.id)).FirstOrDefault(); credito.CAT = data.CAT; credito.descripcion = data.descripcion; credito.edad = data.edad; credito.esquemaDeCobro = data.esquemaDeCobro; credito.frecuenciasDePago = data.frecuenciasDePago; credito.grantiaPersonalAval = data.grantiaPersonalAval; credito.lapMaxSemanas = data.lapMaxSemanas; credito.lapMinSemanas = data.lapMinSemanas; credito.montoCredito = data.montoCredito; credito.numeroDeIntegrantes = data.numeroDeIntegrantes; credito.otrasComisones = data.otrasComisones; credito.plazoMaximo = data.plazoMaximo; credito.plazoMinimo = data.plazoMinimo; credito.requisitos = data.requisitos; credito.soloclientes = data.soloclientes; credito.tasaDeInteres = data.tasaDeInteres; credito.tencologiaCrediticia = data.tencologiaCrediticia; credito.tipocredito = data.tipocredito; credito.tipoRetornoPago28Dias = data.tipoRetornoPago28Dias; credito.tipoRetornoPagoCatorcenal = data.tipoRetornoPagoCatorcenal; credito.tipoRetornoPagoSemanal = data.tipoRetornoPagoSemanal; credito.title = data.title; db.SaveChanges(); var action = "UPDATE"; var comments = "Producto Financiero actualizado por el usuario : "; InsertInBitacora(data.id_userCreated, action, comments + data.id_userCreated); return(RedirectToAction("Details", "ProductoFinanciero", new { id = data.id })); } } else { using (DBEnt db = new DBEnt()) { var credito = db.HomeProductosFinancieros.ToList <HomeProductosFinancieros>().Where(u => u.id.Equals(data.id)).FirstOrDefault(); var filedelete = credito.img; System.IO.File.Delete(filedelete); DateTime dtime = new DateTime(); dtime = DateTime.Now; int idint = RandomNumber(1, 1000000000); string id = idint.ToString(); string filename = "" + "_" + id + "_" + String.Format("{0:d}", dtime) + data.files.FileName; filename = filename.Replace("/", "_"); try { fx.SaveAs(Path.Combine(@"C:\Users\EjeDesarrolloCS-162\source\repos\WebFiles\Creditos", filename)); } catch (Exception) { throw; } var img = "/files/Creditos/" + filename; credito.img = img; credito.CAT = data.CAT; credito.descripcion = data.descripcion; credito.edad = data.edad; credito.esquemaDeCobro = data.esquemaDeCobro; credito.frecuenciasDePago = data.frecuenciasDePago; credito.grantiaPersonalAval = data.grantiaPersonalAval; credito.lapMaxSemanas = data.lapMaxSemanas; credito.lapMinSemanas = data.lapMinSemanas; credito.montoCredito = data.montoCredito; credito.numeroDeIntegrantes = data.numeroDeIntegrantes; credito.otrasComisones = data.otrasComisones; credito.plazoMaximo = data.plazoMaximo; credito.plazoMinimo = data.plazoMinimo; credito.requisitos = data.requisitos; credito.soloclientes = data.soloclientes; credito.tasaDeInteres = data.tasaDeInteres; credito.tencologiaCrediticia = data.tencologiaCrediticia; credito.tipocredito = data.tipocredito; credito.tipoRetornoPago28Dias = data.tipoRetornoPago28Dias; credito.tipoRetornoPagoCatorcenal = data.tipoRetornoPagoCatorcenal; credito.tipoRetornoPagoSemanal = data.tipoRetornoPagoSemanal; credito.title = data.title; var action = "UPDATE"; var comments = "Producto Financiero actualizado por el usuario : "; InsertInBitacora(data.id_userCreated, action, comments + data.id_userCreated); db.SaveChanges(); return(RedirectToAction("Details", "ProductoFinanciero", new { id = data.id })); } } }
public ActionResult editExam(long?id, ExamViewModel collection) { DBEnt db = new DBEnt(); var exam = db.Exams.Where(x => x.Id == id).FirstOrDefault(); if (collection.Image != null) { if (!examExist(collection.Name)) { string filename = Path.GetFileNameWithoutExtension(collection.Image.FileName); string ext = Path.GetExtension(collection.Image.FileName); filename = filename + DateTime.Now.Millisecond.ToString(); filename = filename + ext; string filetodb = "/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image/"), filename); collection.Image.SaveAs(filename); collection.Cover = filetodb; exam.Name = collection.Name; exam.Cover = collection.Cover; exam.MarkPerMcq = collection.MarkPerMcq; exam.NegativeMark = collection.NegativeMark; exam.TimeInMinutes = collection.TimeInMinutes; db.SaveChanges(); Alerts.examupdated = true; return(RedirectToAction("addExam", "Admin")); } else { if (collection.Image != null) { string filename = Path.GetFileNameWithoutExtension(collection.Image.FileName); string ext = Path.GetExtension(collection.Image.FileName); filename = filename + DateTime.Now.Millisecond.ToString(); filename = filename + ext; string filetodb = "/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image/"), filename); collection.Image.SaveAs(filename); collection.Cover = filetodb; exam.Cover = collection.Cover; exam.MarkPerMcq = collection.MarkPerMcq; exam.NegativeMark = collection.NegativeMark; exam.TimeInMinutes = collection.TimeInMinutes; db.SaveChanges(); Alerts.examupdated = true; return(RedirectToAction("addExam", "Admin")); } Alerts.alreadyExist = true; return(RedirectToAction("addExam", "Admin")); } } else { if (!examExist(collection.Name)) { exam.Name = collection.Name; exam.MarkPerMcq = collection.MarkPerMcq; exam.NegativeMark = collection.NegativeMark; exam.TimeInMinutes = collection.TimeInMinutes; db.SaveChanges(); Alerts.examupdated = true; return(RedirectToAction("addExam", "Admin")); } else { exam.MarkPerMcq = collection.MarkPerMcq; exam.NegativeMark = collection.NegativeMark; exam.TimeInMinutes = collection.TimeInMinutes; db.SaveChanges(); Alerts.alreadyExist = true; return(RedirectToAction("addExam", "Admin")); } } return(View()); }