public ActionResult RecentQuestions(Guid ownerId) { IList <QuestionListModel> models = new ListStack <QuestionListModel>(); var context = new StackOverflowContext(); var que = context.Questions.Include(r => r.Owner).OrderByDescending(y => y.CreationDate).ToList(); int i, count = 0; for (i = 0; i < que.Count; i++) { if (count >= 5 || que.ElementAt(i).Owner.Id != ownerId) { break; } QuestionListModel model = new QuestionListModel(); model.Title = que.ElementAt(i).Title; model.Votes = que.ElementAt(i).Votes; model.CreationTime = que.ElementAt(i).CreationDate; model.OwnerName = que.ElementAt(i).Owner.Name; model.QuestionId = que.ElementAt(i).Id; model.OwnerId = que.ElementAt(i).Owner.Id; model.Views = que.ElementAt(i).NumberOfViews; var trimmed = que.ElementAt(i).Description.Trim(); var substring = trimmed.Substring(0, Math.Min(10, trimmed.Length)); model.QuestionPreview = substring + "..."; count++; models.Add(model); } return(PartialView(models)); }
public List <GroupDto> GetGroupDtoList(List <Group> groups, int userId) { List <GroupDto> groupsDto = new ListStack <GroupDto>(); groups.ForEach(g => groupsDto.Add(GetGroupInDto(g, userId))); return(groupsDto); }
public List <Interwaly> GetAllInterwals() { using (PP_testEntities context = new PP_testEntities()) { List <Interwaly> list = new ListStack <Interwaly>(); foreach (var c in context.Interwalies) { list.Add(c); } return(list); } }
public List <dynamic> Get() { List <dynamic> reviews = new ListStack <dynamic>(); reviews.Add(new { CustomerId = 1021, Product = "WOODSCENTZ", ReviewText = "Brut is a classic mens scent.", Score = 4 }); reviews.Add(new { CustomerId = 1022, Product = "WOODSCENTZ", ReviewText = "I dont dislike this scent by any means - its perfectly nice.", Score = 5 }); return(reviews); }
public List <dynamic> Get() { var customerDashboard = new ListStack <dynamic>(); customerDashboard.Add(new { CommentPercentage = 0, MeanScore = 3.55, NoOfComments = 4918, NoOfUsers = 3143, UserPercentage = 0 }); return(customerDashboard); }
public List <UnitTreeItemModel> GetChildrenEmployeeList(List <UnitTreeItemModel> childEmployees, Guid?departamentId) { List <List <UnitTreeItemModel> > BranchList = new List <List <UnitTreeItemModel> >(); List <UnitTreeItemModel> unitBranch; UnitTreeItemModel parentUnit = new UnitTreeItemModel(); List <UnitTreeItemModel> result = new ListStack <UnitTreeItemModel>(); int index = 0; foreach (var employee in childEmployees) { unitBranch = new List <UnitTreeItemModel>(); parentUnit = employee; unitBranch.Add(parentUnit); while (parentUnit.ParentId != null || parentUnit.id == departamentId) { parentUnit = (from e in db.Units where (e.Id == parentUnit.ParentId) select new UnitTreeItemModel() { id = e.Id, Type = e.Type, DataId = e.Id, expanded = true, Name = e.DisplayName, hasChildren = true, ParentId = e.ParentId, }).First(); unitBranch.Add(parentUnit); } BranchList.Add(unitBranch); } foreach (var item in BranchList) { foreach (var unit in item) { if (unit.id == departamentId) { index = item.IndexOf(unit); if (item[index - 1].Type == 1) { result.Add(item.First()); } } } } return(result); }
// // GET: /Answer/ public ActionResult AnswerIndex(string id) { TempData["QuestionRef"] = id; int count = 1; IList <AnswerListModel> models = new ListStack <AnswerListModel>(); var context = new StackOverflowContext(); var ans = context.Answers.Include(r => r.Owner).Include(r => r.QuestionReference); ans = ans.OrderByDescending(x => x.IsBestAnswer).ThenByDescending(y => y.Votes) .ThenByDescending(z => z.CreationDate); foreach (Answer q in ans) { if (Guid.Parse(id) != q.QuestionReference.Id) { continue; } var model = new AnswerListModel(); model.AnswerCount = "Answer " + (count++); if (q.IsBestAnswer) { model.BestAnswer = "Best Answer"; } else { model.BestAnswer = ""; } model.CreationDate = q.CreationDate; model.OwnerName = q.Owner.Name; model.Votes = q.Votes; model.OwnerId = q.Owner.Id; model.AnswerId = q.Id; model.QuestionId = q.QuestionReference.Id; model.AnswerText = q.AnswerText; model.QuestionOwnerId = q.QuestionReference.Owner.Id; model.UserHasVoted = AnswerHasBeenVoted(model.AnswerId); models.Add(model); } context.SaveChanges(); return(PartialView(models)); }
public ActionResult RecentAnswers(Guid ownerId) { IList <AnswerListModel> models = new ListStack <AnswerListModel>(); var context = new StackOverflowContext(); var ans = context.Answers.Include(r => r.Owner).Include(r => r.QuestionReference); ans = ans.OrderByDescending(z => z.CreationDate); int cont = 0; foreach (Answer q in ans) { if (ownerId != q.Owner.Id) { continue; } if (cont >= 5) { break; } var model = new AnswerListModel(); if (q.IsBestAnswer) { model.BestAnswer = "Best Answer"; } else { model.BestAnswer = ""; } model.CreationDate = q.CreationDate; model.OwnerName = q.Owner.Name; model.Votes = q.Votes; model.OwnerId = q.Owner.Id; model.AnswerId = q.Id; model.QuestionId = q.QuestionReference.Id; model.AnswerText = q.AnswerText; model.QuestionOwnerId = q.QuestionReference.Owner.Id; models.Add(model); cont++; } return(PartialView(models)); }
public string ApplyInComing(List <Apply_Info> applyInfos) { if (applyInfos == null) { return("OK"); } List <Apply_Info> newApplyInfos = new ListStack <Apply_Info>(); foreach (Apply_Info applyInfo in applyInfos) { if (newApplyInfos.Count(m => m.ApplyType_Id == applyInfo.ApplyType_Id && m.Apply_Id == applyInfo.Apply_Id) == 0) { newApplyInfos.Add(applyInfo); } else { Apply_Info apply = newApplyInfos.FirstOrDefault(m => m.ApplyType_Id == applyInfo.ApplyType_Id && m.Apply_Id == applyInfo.Apply_Id); if (apply != null) { apply.Apply_Count = apply.Apply_Count + applyInfo.Apply_Count; } } } List <BuyInComing_Apply> buyInComingApplies = new List <BuyInComing_Apply>(); foreach (Apply_Info applyInfo in newApplyInfos) { BuyInComing_Apply buyInComingApply = _buyInComingApplyBll.Find(applyInfo.Apply_Id); buyInComingApply.Is_Bought = true; buyInComingApplies.Add(buyInComingApply); } return(_applyInfoBll.AddEntities(newApplyInfos) && _buyInComingApplyBll.UpdateEntities(buyInComingApplies) ? "OK" : "Error"); }
private static List<string> GetClassesForDay(int numOfDay) { HtmlNode table; using (WebClient client = new WebClient()) { HtmlDocument html = new HtmlDocument(); html.LoadHtml(client.DownloadString("http://bikram.hu/?p=orarend")); table = html.DocumentNode.SelectSingleNode("//*[@id=\"ora\"]"); } HtmlNodeCollection startTimes = table.SelectNodes(".//tr/td[1]"); HtmlNodeCollection todayColumn = table.SelectNodes(".//tr/td[" + (numOfDay + 1) + "]"); List<string> startList = new List<string>(); startList.AddRange(startTimes.Select(n => n.InnerText)); List<string> todayList = new List<string>(); todayList.AddRange(todayColumn.Select(n => n.InnerText)); List<string> result = new ListStack<string>(); for (int i = 0; i < startList.Count; i++) { startList[i] = startList[i].Replace(".", ":"); } for (int i = 0; i < todayList.Count; i++) { if (todayList[i] != " ") { result.Add(string.Concat(startList[i], " ", todayList[i])); } } return result; }
public ActionResult Index(int start = 0, int type = 0) { IList <QuestionListModel> models = new ListStack <QuestionListModel>(); var context = new StackOverflowContext(); var context2 = new StackOverflowContext(); List <Question> que = new List <Question>(); switch (type) { case 0: que = context.Questions.Include(r => r.Owner) .OrderByDescending(x => x.CreationDate).ToList(); break; case 1: que = context.Questions.Include(r => r.Owner) .OrderByDescending(x => x.NumberOfViews).ToList(); break; case 2: que = context.Questions.Include(r => r.Owner) .OrderByDescending(x => x.Votes).ToList(); break; case 3: que = context.Questions.Include(r => r.Owner) .OrderByDescending(x => x.CreationDate).ToList(); break; } var hasAvailable = true; //foreach (Question q in que) //{ // QuestionListModel model = new QuestionListModel(); // model.Title = q.Title; // model.Votes = q.Votes; // model.CreationTime = q.CreationDate; // model.OwnerName = q.Owner.Name; // model.QuestionId = q.Id; // model.OwnerId = q.Owner.Id; // models.Add(model); //} int i; for (i = 0; i < start + 25; i++) { if (i == que.Count) { hasAvailable = false; break; } QuestionListModel model = new QuestionListModel(); model.Title = que.ElementAt(i).Title; model.Votes = que.ElementAt(i).Votes; model.CreationTime = que.ElementAt(i).CreationDate; model.OwnerName = que.ElementAt(i).Owner.Name; model.QuestionId = que.ElementAt(i).Id; model.OwnerId = que.ElementAt(i).Owner.Id; model.Views = que.ElementAt(i).NumberOfViews; var trimmed = que.ElementAt(i).Description.Trim(); var substring = trimmed.Substring(0, Math.Min(10, trimmed.Length)); model.AnswerCount = AnswerCount(model.QuestionId); model.QuestionPreview = substring + "..."; models.Add(model); } start = i; ViewData["start"] = start.ToString(); ViewData["hasAvailable"] = hasAvailable; return(View(models)); }
public ActionResult UploadStudentExcel(int groupId) { if (Request.Files.Count != 0) { string ext = Path.GetExtension(Request.Files[0].FileName); var validExtensions = new[] { ".xlsx", ".xls", "csv" }; if (!validExtensions.Contains(ext)) { TempData["FailUpload"] = "Невірний формат файлу! Тільки файли створенні за допомогою Excel підтримуються (.xlsx ; .xls)"; return(RedirectToAction("Students")); } var file = Request.Files[0]; MemoryStream mem = new MemoryStream(); mem.SetLength((int)file.ContentLength); file.InputStream.Read(mem.GetBuffer(), 0, (int)file.ContentLength); try { using (ExcelPackage p = new ExcelPackage(mem)) { { ExcelWorksheet ws = p.Workbook.Worksheets[1]; var specialityId = Context.Groups.FirstOrDefault(t => t.Id == groupId).SpecialityId; var students = Context.Students.Where(t => t.GroupId == groupId && t.SpecialityId == specialityId).ToList(); var accounts = Context.Accounts.ToList(); List <int> ids = new ListStack <int>(); for (int i = 0; i < 100; i++) { if (ws.Cells[3 + i, 1].Value == null) { break; } var name = ws.Cells[3 + i, 2].Value.ToString(); var surname = ws.Cells[3 + i, 1].Value.ToString(); var studId = Convert.ToInt32(ws.Cells[3 + i, 3].Value); var login = Convert.ToString(ws.Cells[3 + i, 4].Value); var password = Convert.ToString(ws.Cells[3 + i, 5].Value); ids.Add(studId); if (!students.Any(t => t.Id == studId) && studId == 0) { _adding.AddNewStudent(name.TrimEnd().TrimStart(), surname.TrimEnd().TrimStart(), groupId, specialityId); } else { var stud = students.FirstOrDefault(t => t.Id == studId); var acc = accounts.FirstOrDefault(t => t.Id == stud.AccountId); if (stud.Name != name || stud.Surname != surname || acc.Login == login || acc.Password == password) { _editing.EditStudent((int)studId, name.TrimEnd().TrimStart(), surname.TrimEnd().TrimStart(), login, password, groupId); } } } foreach (var student in students) { if (!ids.Contains(student.Id)) { _deleting.DeleteStudent(student.Id); } } TempData["Success"] = "Зміни по студентах групи - \"" + Context.Groups.FirstOrDefault(t => t.Id == groupId).Name + "\" було успішно збережено!"; p.Dispose(); } } } catch (Exception) { TempData["FailUpload"] = "Невірне оформлення документу! Будь ласка, завантажте шаблон і заповніть згідно вказаних праввил."; } } return(RedirectToAction("Students")); }