public static List <Books> getBookList1() { dbEntities db = new dbEntities(); List <Books> list = db.Books.Where(a => a.Price < 20).ToList <Books>(); return(list); }
public ActionResult CreateBid([Bind(Include = "BidId, StartingPrice, LowestPrice, UserId, JobId, Title, EmployeerID, JobDesc, CanBid")] BiddingPageViewModel model) { BiddingPageViewModel OldData = (BiddingPageViewModel)TempData["BiddingPageViewModel"]; //persisted data using (dbEntities db = new dbEntities()) { if (ModelState.IsValid && OldData.CanBid == 1) { int id2 = db.Bids.Count(); Bid bid = new Bid() { Id = id2 + 1, Price = model.StartingPrice, UserId = (int)Session["loginid"], //UNCOMMENT THIS UPON MERGE AND DELETE ABOVE LINE JobId = OldData.JobId }; db.Bids.Add(bid); db.SaveChanges(); return(RedirectToAction("Display", "DisplayJob", new { id = OldData.JobId })); //parameter will send to ajay view for specific job needs to come up with it } return(View()); //redirect to partial view possibly for error handling } }
public static void update2(Books entry) { dbEntities dc = new dbEntities(); dc.Entry <Books>(entry).State = System.Data.EntityState.Modified; dc.SaveChanges(); }
public static void update3(Books entry) { dbEntities dc = new dbEntities(); db.lib.efHelper.entryUpdate(entry, dc); dc.SaveChanges(); }
public static db.Books getBooks(int id) { dbEntities db = new dbEntities(); Books entry = db.Books.SingleOrDefault(b => b.BookId == id); return(entry); }
public static void insert2(db.Books entry) { dbEntities dc = new dbEntities(); dc.Books.Add(entry); dc.SaveChanges(); }
public static void Register(int type, string firstName, string lastName, string email, string password) { if (type != (int)logic.Constants.Types.AccountTypes.Student && type != (int)logic.Constants.Types.AccountTypes.Teacher) { throw new Exception("Invalid account type."); } firstName = firstName.Trim(); lastName = lastName.Trim(); email = email.Trim(); password = password.Trim(); if (string.IsNullOrEmpty(firstName)) { throw new Exception("First name required."); } if (string.IsNullOrEmpty(lastName)) { throw new Exception("Last name required."); } if (string.IsNullOrEmpty(email)) { throw new Exception("Email required."); } if (string.IsNullOrEmpty(password)) { throw new Exception("Password required."); } if (!Helpers.Strings.EmailValid(email)) { throw new Exception("Email not valid."); } using (var conn = new dbEntities()) { if (conn.Accounts.Any(a => a.Email == email)) { throw new Exception("Email already registered."); } var account = new Account() { AccountType_ID = type, Fname = firstName, Lname = lastName, Email = email, Password = Helpers.PasswordStorage.CreateHash(password) }; conn.Accounts.Add(account); conn.SaveChanges(); // Rules.ZoomApi.CreateZoomUserAccount(account.ID); EventLogging.Register(account); } }
public static List <db.Books> getBooks() { dbEntities db = new dbEntities(); List <Books> list = db.Books.ToList <Books>(); return(list); }
public static MemoryStream DownloadLessonResource(int resourseID) { try { using (var conn = new dbEntities()) { LessonResource resource = new LessonResource(); resource = conn.LessonResources.FirstOrDefault(r => r.ID == resourseID); if (resource == null) { throw new Exception("Lesson resource not found."); } using (var memoryStream = new MemoryStream()) { logic.Helpers.AzureStorage.StoredResources.DownloadLessonResource(memoryStream, resource.Item_Storage_Name); return(memoryStream); } } } catch (Exception ex) { var ignore = ex; } return(null); }
public static void Register(Account user) { using (var conn = new dbEntities()) { conn.Configuration.AutoDetectChangesEnabled = false; conn.Configuration.ValidateOnSaveEnabled = false; conn.EventLogs.Add(new EventLog() { Account_ID = user.ID, Type = Models.Auditing.AccountRegistration.TypeToString(), Data = JsonConvert.SerializeObject( new Models.Auditing.AccountRegistration() { ID = user.ID, AccountType_ID = user.AccountType_ID, AccountType = ((logic.Constants.Types.AccountTypes)user.AccountType_ID).ToString(), Email = user.Email, Fname = user.Fname, Lname = user.Lname }), EventDate = DateTime.UtcNow, IPAddress = Shearnie.Net.Web.ServerInfo.GetIPAddress }); conn.SaveChanges(); } }
public static MemoryStream DownloadProfilePicture(int accountId) { try { using (var conn = new dbEntities()) { var account = new Account(); account = conn.Accounts.FirstOrDefault(r => r.ID == accountId); if (account == null) { throw new Exception("Account not found."); } using (var memoryStream = new MemoryStream()) { if (account.Picture == null) { return(null); } else { logic.Helpers.AzureStorage.StoredResources.DownloadProfilePicture(memoryStream, account.Picture); } return(memoryStream); } } } catch (Exception ex) { var ignore = ex; return(null); } }
public static string UploadResource(int lessonId, HttpPostedFileBase resource) { try { using (var conn = new dbEntities()) { var lesson = conn.Lessons.FirstOrDefault(l => l.ID == lessonId); if (lesson == null) { throw new Exception("Lesson does not exist."); } var lessonResource = new LessonResource() { Lession_ID = lessonId, Original_Name = resource.FileName, Item_Storage_Name = logic.Helpers.AzureStorage.StoredResources.UploadLessonResource(resource), Type_ID = Constants.Types.Default }; conn.LessonResources.Add(lessonResource); conn.SaveChanges(); } return(resource.FileName); } catch (Exception ex) { return(ex.Message); } }
public static string DownloadLessonImage(int resourseID) { try { using (var conn = new dbEntities()) { LessonResource resource = new LessonResource(); resource = conn.LessonResources.FirstOrDefault(r => r.ID == resourseID); if (resource == null) { throw new Exception("Lesson resource not found."); } using (var memoryStream = new MemoryStream()) { logic.Helpers.AzureStorage.StoredResources.DownloadLessonResource(memoryStream, resource.Item_Storage_Name); var imageByte = memoryStream.ToArray(); return(System.Text.Encoding.UTF8.GetString(imageByte, 0, imageByte.Length)); } } } catch (Exception ex) { var ignore = ex; } return(null); }
[HttpGet] //insert route as well? public ActionResult BidGetInfo(int id) //sets up bid creation { using (dbEntities db = new dbEntities()) { double CurrentLowestBid = db.Jobs.Where(o => o.Id == id).Single().StartPrice; List <Bid> temp = db.Jobs.Where(o => o.Id == id).Single().Bids.ToList(); foreach (var b in temp) { if (CurrentLowestBid > b.Price) { CurrentLowestBid = b.Price; } } BiddingPageViewModel SetUp = new BiddingPageViewModel() { BidId = -1, //temp value for now StartingPrice = db.Jobs.Where(o => o.Id == id).Single().StartPrice, LowestPrice = CurrentLowestBid, UserId = (int)Session["loginid"], //UNCOMMENT THIS UPON MERGE AND DELETE ABOVE LINE JobId = id, Title = db.Jobs.Where(o => o.Id == id).Single().Title, EmployerID = db.Jobs.Where(o => o.Id == id).Single().EmployerId, JobDesc = db.Jobs.Where(o => o.Id == id).Single().JobDec, CanBid = db.Jobs.Where(o => o.Id == id).Single().CanBid, }; TempData["BiddingPageViewModel"] = SetUp; return(View("~/Views/Bid/Bid.cshtml", SetUp)); } }
public ActionResult Login(Models.Employee_.Login.ViewModel m) { if (ModelState.IsValid) { SHA256 sha256 = new SHA256Managed(); byte[] hashed = sha256.ComputeHash(Encoding.UTF8.GetBytes(m.Password)); using (var db = new dbEntities()) { // Note: this works as LINQ translates this to a SQL comparison, where byte[] are compared properly. var employee = db.Employees.SingleOrDefault( e => e.Username == m.Username && e.Password == hashed); if (employee == null) { return(View()); } Session.Contents["EmployeeId"] = employee.Id; Session.Contents["EmployeeName"] = employee.Username; Session.Contents["EmployeeAdmin"] = employee.IsAdmin; } return(RedirectToAction("Index", "Home")); } return(View()); }
private void BetStop(bet_stop e, dbEntities cnn, string routeKey) { using (var dbContextTransaction = cnn.Database.BeginTransaction()) { var sectionName = string.Empty; var spParams = string.Empty; try { sectionName = "bet_stop"; spParams = "EXECUTE PROCEDURE BET_EVENTBETSTOP_I("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += e.product + ","; spParams += "'" + e.groups?.Trim() + "',"; spParams += e.market_status + ","; spParams += e.GeneratedAt + ")"; cnn.Database.ExecuteSqlCommand(spParams.Trim()); dbContextTransaction.Commit(); SerilogHelper.Information($"{routeKey} {UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms"}"); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception($"Unknown exception in {routeKey} SectionName:{sectionName} SQL:{spParams.Trim()}", ex); } } }
private void BetCancel(bet_cancel e, dbEntities db, string routeKey) { var sectionName = string.Empty; using (var dbContextTransaction = db.Database.BeginTransaction()) { try { sectionName = "bet_cancel"; foreach (var market in e.market) { var specifier = market.specifiers?.Split('=').LastOrDefault().Trim(); var spParams = "EXECUTE PROCEDURE BET_EVENTBETCANCEL_I("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += e.product + ","; spParams += e.start_time + ","; spParams += e.end_time + ","; spParams += market.id + ","; spParams += "'" + specifier + "',"; spParams += market.void_reason + ","; spParams += e.GeneratedAt + ")"; db.Database.ExecuteSqlCommand(spParams.Trim()); } dbContextTransaction.Commit(); SerilogHelper.Information(string.Format("{0} {1}", routeKey, UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms")); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception(string.Format("Unknown exception in {0} {1} {2}", routeKey, sectionName, e.event_id), ex); } } }
private void ProducerUpDown(ProducerModel e, dbEntities cnn, string routeKey) { var sectionName = string.Empty; using (var dbContextTransaction = cnn.Database.BeginTransaction()) { try { sectionName = "ProducerUpDown"; var spParams = "EXECUTE PROCEDURE BETDATA_ALIVE("; spParams += SourceId + ","; spParams += e.Id + ","; spParams += "'" + e.Description + "',"; spParams += (e.IsAvailable ? 1 : 0) + ","; spParams += (e.IsDisabled ? 1 : 0) + ","; spParams += (e.IsProducerDown ? 1 : 0) + ")"; cnn.Database.ExecuteSqlCommand(spParams.Trim()); dbContextTransaction.Commit(); SerilogHelper.Information(string.Format("ProducerUpDown ID:{0} Description:{1} IsAvailable:{2} IsDisabled:{3} IsProducerDown:{4}", e.Id, e.Description, e.IsAvailable, e.IsDisabled, e.IsProducerDown)); SerilogHelper.Information(string.Format("{0}", routeKey)); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception(string.Format("Unknown exception in {0}", sectionName), ex); } } }
private void FixtureChange(fixture_change e, dbEntities db, string routeKey) { var sectionName = string.Empty; using (var dbContextTransaction = db.Database.BeginTransaction()) { try { sectionName = "fixture_change"; var spParams = "EXECUTE PROCEDURE BET_EVENTFIXTURECHANGE_I("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += e.product + ","; spParams += e.change_type + ","; spParams += e.GeneratedAt + ")"; db.Database.ExecuteSqlCommand(spParams.Trim()); dbContextTransaction.Commit(); SerilogHelper.Information(string.Format("{0} {1}", routeKey, UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms")); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception(string.Format("Unknown exception in {0} {1} {2}", routeKey, sectionName, e.event_id), ex); } } }
private void BetSettlement(bet_settlement e, dbEntities db, string routeKey) { using (var dbContextTransaction = db.Database.BeginTransaction()) { var sectionName = string.Empty; var spParams = string.Empty; try { var marketIdList = string.Empty; var specifierList = string.Empty; var outcomeIdList = string.Empty; var resultList = string.Empty; var certaintyList = string.Empty; var productList = string.Empty; foreach (var market in e.outcomes) { var marketId = market.id; var specifier = market.specifiers?.Split('=').LastOrDefault()?.Trim(); foreach (var outcome in market.Items) { marketIdList += marketId + ","; specifierList += specifier + ","; outcomeIdList += outcome.id.Split(':').LastOrDefault() + ","; resultList += outcome.result + ","; certaintyList += e.certainty + ","; productList += e.product + ","; marketId = 0; if (!string.IsNullOrEmpty(specifier)) { specifier = "*"; } } } sectionName = "bet_settlement"; spParams = "EXECUTE PROCEDURE BET_EVENTRESULTS_I_MULTI("; spParams += SourceId + ","; spParams += e.event_id.Split(':').Last() + ","; spParams += "'" + marketIdList.Substring(0).Trim() + "',"; spParams += "'" + specifierList.Substring(0).Trim() + "',"; spParams += "'" + outcomeIdList.Substring(0).Trim() + "',"; spParams += "'" + resultList.Substring(0).Trim() + "',"; spParams += "'" + certaintyList.Substring(0).Trim() + "',"; spParams += "'" + productList.Substring(0).Trim() + "',"; spParams += e.GeneratedAt + ")"; db.Database.ExecuteSqlCommand(spParams.Trim()); dbContextTransaction.Commit(); SerilogHelper.Information($"{routeKey} {UtcHelper.GetDifferenceFromTimestamp(e.timestamp) + "ms"}"); } catch (Exception ex) { dbContextTransaction.Rollback(); SerilogHelper.Exception($"Unknown exception in {routeKey} SectionName:{sectionName} SQL:{spParams.Trim()}", ex); } } }
public ActionResult MessagePageDisplayAuto(int Jobid) { using (dbEntities db = new dbEntities()) { int user = (int)Session["loginid"]; UserMessagesVeiwModel temp = new UserMessagesVeiwModel(); temp.Inbox = new List <Messaging>(); temp.Sent = new List <Messaging>(); List <Messaging> x = db.Users.Where(o => o.Id == user).Single().Messagings.ToList(); List <Messaging> y = db.Users.Where(o => o.Id == user).Single().Messagings1.ToList(); foreach (var t in x) { temp.Inbox.Add(t); } foreach (var q in y) { temp.Sent.Add(q); } temp.Jobtitle = db.Jobs.Where(o => o.Id == Jobid).Single().Title; temp.Msg.ReceiverId = db.Jobs.Where(o => o.Id == Jobid).Single().EmployerId; temp.Msg = null; temp.ErrorLoadingPage = null; return(View("~/Views/Msg/ComposeMsgView.cshtml", temp)); } }
public void FeedLoQueueToDb() { while (true) { try { if (!Program.feedLoQueue.Any()) { continue; } using (var db = new dbEntities()) { db.Database.Log = SerilogHelper.Verbose; while (Program.feedLoQueue.TryDequeue(out var feed)) { var typeName = feed.RouteKey.Split('.').Skip(3).FirstOrDefault(); RouteTheKey(typeName, feed, db); if (Program.feedLoQueue.Count() > 10) { SerilogHelper.Error($"{Program.feedLoQueue.Count()} -> Queue count for feedLoQueue"); } } } } catch (Exception ex) { SerilogHelper.Exception("FeedLoQueueToDb", $"Error when importing process!", ex); } } }
public ActionResult Login(user objUser) { if (ModelState.IsValid) { using (dbEntities db = new dbEntities()) { var UserN = objUser.username; var UserP = objUser.password; var obj = db.users.Where(a => a.username.Equals(UserN) && a.password.Equals(UserP)).FirstOrDefault(); if (obj != null) { Session["Id"] = obj.id; Session["userName"] = obj.username.ToString(); Session["userLevel"] = obj.userLevel; Session["registeredGiveaway"] = obj.fk_giveaway; if (obj.userLevel == 1) { return(RedirectToAction("UserDashBoard")); } else { return(RedirectToAction("AdminDashBoard")); } } } } return(View(objUser)); }
public ActionResult DisplayMessage(int id) //passed in by the current id for the message to be viewed { using (dbEntities db = new dbEntities()) { SingleMessageDisplayViewModel message = new SingleMessageDisplayViewModel { Msg = new Messaging() }; message.Msg = db.Messagings.Where(o => o.Id == id).Single(); int sender = message.Msg.SenderId; int user = (int)Session["loginid"]; if (sender != (int)Session["loginid"]) { int y = message.Msg.ReceiverId; message.ReceipientName = db.Users.Where(o => o.Id == y).Single().FirstName + " " + db.Users.Where(o => o.Id == y).Single().LastName;; string t = db.Users.Where(o => o.Id == user).Single().FirstName + " " + db.Users.Where(o => o.Id == user).Single().LastName; message.SenderName = t; } else { int te = message.Msg.SenderId; string w = db.Users.Where(o => o.Id == te).Single().FirstName + " " + db.Users.Where(o => o.Id == te).Single().LastName; message.SenderName = w; message.ReceipientName = db.Users.Where(o => o.Id == sender).Single().FirstName + " " + db.Users.Where(o => o.Id == sender).Single().LastName; } return(View("~/Views/Msg/MsgDisplayView.cshtml", message)); } }
public ActionResult Registrar(Unitunes.Models.Academico academico) { //verifica se existe o registro //quando enviar o post if (ModelState.IsValid) { var ctx = new dbEntities(); var academicos = ctx.AcademicoSet; //verifica se usuario nao existe if (!Unitunes.Models.Servicos.Academico.isAcademicoExists(academico)) { //cria usuario Unitunes.Models.Servicos.Academico.adicionarAcademico(academico); Unitunes.Models.Servicos.Academico.autenticar(academico); return(Redirect("/Login/Principal")); } else { ModelState.AddModelError("error", "Usuario Já existe"); } } else { ModelState.AddModelError("error", "Preencha o formulario corretamente"); } // The action is a POST. return(View()); }
public ViewModels.Profile.LessonDetails LoadLessonDetails(int id, int loggedInUserId) { var ret = new ViewModels.Profile.LessonDetails(); using (var conn = new dbEntities()) { ret.lesson = conn.Lessons.AsNoTracking().FirstOrDefault(l => l.ID == id); if (ret.lesson == null) { throw new Exception("Lesson does not exist."); } if (ret.lesson.Account_ID != loggedInUserId) { throw new WrongAccountException(); } // timezone out for displaying ret.lesson.BookingDate = Rules.Timezone.ConvertFromUTC(ret.lesson.BookingDate); foreach (var participant in ret.lesson.LessonParticipants.ToList()) { var other = conn.Accounts.FirstOrDefault(a => a.ID == participant.Account_ID); if (other != null) { ret.others.Add(other); } } ret.chatRecords = ret.lesson.ChatRecords.ToList(); } return(ret); }
internal static Student SearchStudent(int ID) { using (dbEntities entity = new dbEntities()) { var result = (from i in entity.student_tbl where i.StudentId == ID & i.StatusId == 1 select i).SingleOrDefault(); if (result == null) { return(null); } else { return(new Student { ID = result.StudentId, Name = result.Name, Surname = result.Surname, Gender = result.Gender, Cell = result.Cell, Email = result.Email, PostalAddress = result.PostallAddress, CourseId = result.CourseId, Semester = result.Semester, StatusId = result.StatusId }); } } }
internal static List <Course> GetCourses() { List <Course> cs = new List <Course>(); using (dbEntities d = new dbEntities()) { var e = (from i in d.course_tble where i.StatusId == 1 select i).ToList <course_tble>(); foreach (var item in e) { cs.Add(new Course { CourseId = item.CourseId, CourseCode = item.CourseCode, CourseName = item.CourseName, Duration = item.CourseDuration, StatusId = item.StatusId }); } return(cs); } }
internal static List <Teacher> GetTeachers() { List <Teacher> studl = new List <Teacher>(); using (dbEntities ent = new dbEntities()) { var results = (from s in ent.teacher_tbl where s.StatusId == 1 select s).ToList <teacher_tbl>(); foreach (var item in results) { studl.Add(new Teacher { ID = item.TeacherId, Name = item.Name, Surname = item.Surname, Gender = item.Gender, Cell = item.Cell, Email = item.Email, PIN = item.PIN, StatusId = item.StatusId }); } return(studl); } }
internal static List <Student> GetStudents() { List <Student> studl = new List <Student>(); using (dbEntities ent = new dbEntities()) { var results = (from s in ent.student_tbl where s.StatusId == 1 select s).ToList <student_tbl>(); foreach (var item in results) { studl.Add(new Student { ID = item.StudentId, Name = item.Name, Surname = item.Surname, Gender = item.Gender, Cell = item.Cell, Email = item.Email, PostalAddress = item.PostallAddress, CourseId = item.CourseId, Semester = item.Semester, StatusId = item.StatusId }); } return(studl); } }
protected void btnLogin_Click(object sender, EventArgs e) { dbEntities db = new dbEntities(); ObjectSet<User> d = db.Users; foreach (User u in d) { Console.WriteLine(u.email); } Session["isLoggedIn"] = 1; Response.Redirect("home.aspx"); }
public ActionResult Email(Email email) { var db = new dbEntities(); db.AddToForwardedEmails(new ForwardedEmail() { Created = DateTime.Now, From = email.From, Plain = email.Plain, Subject = email.Subject }); db.SaveChanges(); return new EmptyResult(); }