public async Task <IActionResult> Edit(int id, SeminarViewModel model) { int seminarId = model.Seminar.SeminarId; if (id != seminarId) { return(NotFound()); } if (ModelState.IsValid) { if (model.Uid != "") { model.Seminar.Name = model.Seminar.Name.Prepend(model.Uid); } try { await _db.UpdateSeminarAsync(model); } catch (Exception) { return(RedirectToAction(nameof(Index))); } return(Redirect(model.LastPage)); } return(View(model)); }
public ActionResult Seminari() { List <Seminar> seminari = new List <Seminar>(); List <SeminarViewModel> seminariViewModel = new List <SeminarViewModel>(); using (ApplicationDbContext _db = new ApplicationDbContext()) { seminari = _db.Seminar.ToList(); foreach (var item in seminari) { SeminarViewModel seminarViewModel = new SeminarViewModel(); seminarViewModel.IdSeminar = item.IdSeminar; seminarViewModel.Objava = item.Objava; seminarViewModel.Naziv = item.Naziv; seminarViewModel.Opis = item.Opis; seminarViewModel.Datum = item.Datum; seminarViewModel.MaxBrojPolaznika = item.MaxBrojPolaznika; seminarViewModel.Popunjen = item.Popunjen; seminarViewModel.UkupanBrojPredbiljezbi = item.Predbiljezbe.Count(); //dodajemo ukupan broj predbilježbi i šaljemo na popis seminara seminarViewModel.BrojOdobrenihPredbiljezbi = item.Predbiljezbe.Count(m => m.StatusPredbiljezbe == EnumStatusPredbiljezbe.Prihvacena); //dodajemo broj odobrenih predbilježbi i šaljemo na popis seminara seminarViewModel.BrojNeobradjenihPredbiljezbi = item.Predbiljezbe.Count(m => m.StatusPredbiljezbe == EnumStatusPredbiljezbe.Neobradjena); //dodajemo broj neobrađenih predbilježbi i šaljemo na popis seminara seminariViewModel.Add(seminarViewModel); } } return(View(seminariViewModel)); }
public async Task UpdateSeminarAsync(SeminarViewModel model) { await UpdateAsync(model.Seminar); var seminarDays = await _context.SeminarDays.ToListAsync(); model.CheckList.ForEach(async item => { var existingEntry = seminarDays .FirstOrDefault(x => x.SeminarId == model.Seminar.SeminarId && x.DayId == item.Id); if (!item.IsSelected && existingEntry != null) { await RemoveAsync(existingEntry); } if (item.IsSelected && existingEntry == null) { SeminarDay ds = new SeminarDay() { SeminarId = model.Seminar.SeminarId, DayId = item.Id }; _context.Add(ds); } }); await _context.SaveChangesAsync(); }
public IActionResult Save([FromForm] SeminarViewModel obj) { if (obj.Teacher == 0) { ModelState.AddModelError("TeacherID", "You need to select a teacher for this seminar!"); } if (obj.Attendees.Count == 0) { ModelState.AddModelError("Attendees", "Your need to add at least one attendee to this seminar!"); } if (!ModelState.IsValid) { ViewBag.Persons = repository.Persons.All(); return(View("Edit", obj)); } var seminar = SeminarViewModel.Convert(obj); repository.Seminars.Save(seminar); repository.Attendees.Save(seminar.ID, obj.Attendees); return(Redirect("Index")); }
//Edit seminara za zaposlenike public ActionResult EditSeminar(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Seminar seminar = _db.Seminars.Find(id); List <Zaposlenik> zaposlenici = _db.Zaposleniks.ToList(); SeminarViewModel editSeminar = new SeminarViewModel() { IdSeminar = seminar.IdSeminar, Naziv = seminar.Naziv, Datum = seminar.Datum, Opis = seminar.Opis, Popunjen = seminar.Popunjen, SelectedZaposlenikId = seminar.IdZaposlenik }; editSeminar.Zaposlenici = new SelectList(zaposlenici, "IdZaposlenik", "Ime"); if (seminar == null) { return(HttpNotFound()); } return(View(editSeminar)); }
public async Task <IActionResult> DeleteConfirmed(SeminarViewModel model) { var seminar = await _db.GetSeminarAndDaysAsync(model.Seminar.SeminarId); await _db.RemoveAsync(seminar); return(Redirect(model.LastPage)); }
public async Task Create_stores_new_Seminar() { var seminarView = new SeminarViewModel(Seminar7, new List <Day>(), "", "http://completevocaltraining.nl"); await Controller.Create(seminarView); Context.Seminars.Should().HaveCount(4); }
public async Task Create_stores_Seminar_with_correct_properties() { var seminarView = new SeminarViewModel(Seminar7, new List <Day>(), "", "http://completevocaltraining.nl"); await Controller.Create(seminarView); Context.Seminars.FirstOrDefault(x => x.SeminarId == 7).Should().BeEquivalentTo(Seminar7); }
public IActionResult Add() { var obj = new SeminarViewModel(); ViewBag.Persons = repository.Persons.All(); return(View("Edit", obj)); }
// GET: Upisi public async Task <ActionResult> Index(int?active, int page = 1) { SeminarViewModel model = new SeminarViewModel(); if (active == 0) { ViewBag.Active = "nonactive"; var all = await clientSeminar.GetAllAsync(); var chekMe = all.Where(p => p.Popunjen == false).OrderByDescending(p => p.Datum).Skip((page - 1) * pageSize).Take(pageSize); model.seminar = chekMe; model.pagingInfo = new PagingInfo() { TotalItems = all.Where(s => s.Popunjen == false).Count(), ItemPerPage = pageSize, CurrentPage = page }; return(View(model)); } else if (active == 1) { ViewBag.Active = "active"; var all = await clientSeminar.GetAllAsync(); var checkMe = all.Where(p => p.Popunjen == true).OrderByDescending(p => p.Datum).Skip((page - 1) * pageSize).Take(pageSize); model.seminar = checkMe; model.pagingInfo = new PagingInfo() { TotalItems = all.Where(s => s.Popunjen == true).Count(), ItemPerPage = pageSize, CurrentPage = page }; return(View(model)); } else { ViewBag.Active = "all"; var all = await clientSeminar.GetAllAsync(); var checkMe = all.OrderByDescending(p => p.Datum).Skip((page - 1) * pageSize).Take(pageSize); model.seminar = checkMe; model.pagingInfo = new PagingInfo() { TotalItems = all.Count(), ItemPerPage = pageSize, CurrentPage = page }; return(View(model)); } }
public async Task <IActionResult> Create(SeminarViewModel model) { if (ModelState.IsValid) { await _db.AddSeminarAsync(model); return(Redirect(model.LastPage)); } return(View(model)); }
public void Post([FromBody] SeminarViewModel SeminarVM) { using (var context = new ApplicationDbContext()) { var seminar = new Seminar { Title = SeminarVM.Title, Description = SeminarVM.Description, Date = SeminarVM.Date, Duration = SeminarVM.Duration }; context.Seminars.Add(seminar); context.SaveChanges(); } }
public ActionResult <object> PutSeminar(int id, SeminarViewModel seminarVM) { var message = "Updated " + seminarVM.name + " successfully!"; var stringDate = seminarVM.Date + " " + seminarVM.Time + ":00"; var day = new Day { day = Convert.ToDateTime(stringDate) }; var speaker = new Speaker(); var existingSpeaker = _context.Speakers.Where(s => s.name == seminarVM.SpeakersName).FirstOrDefault(); var existingSeminar = _context.Seminars.Where(s => s.id == id).FirstOrDefault(); if (existingSpeaker == null) { speaker.name = seminarVM.SpeakersName; _context.Speakers.Add(speaker); } else { speaker = existingSpeaker; } if (existingSeminar != null) { existingSeminar.name = seminarVM.name; existingSeminar.description = seminarVM.description; existingSeminar.speaker = speaker; existingSeminar.day = day; } else { return(BadRequest()); } _context.Entry(existingSeminar).State = EntityState.Modified; try { _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SeminarExists(id)) { return(NotFound()); } else { throw; } } return(Ok(new { message })); }
public async Task Edit_returns_NotFound_if_Id_changes() { var s = Context.Seminars.FirstOrDefault(x => x.SeminarId == 1); var seminarView = new SeminarViewModel { Seminar = s, CheckList = new List <CheckedId>() }; var result = await Controller.Edit(8, seminarView); result.Should().BeOfType <NotFoundResult>(); }
public async Task <ActionResult> Edit(SeminarViewModel seminarViewModel) { try { await seminarService.UpdateAsync(mapper.Map <SeminarDTO>(seminarViewModel)); return(RedirectToAction(nameof(Seminar))); } catch { return(View()); } }
//Kreiranje novog seminara za zaposlenike public ActionResult Create() { List <Zaposlenik> zaposlenici = _db.Zaposleniks.ToList(); SeminarViewModel noviSeminar = new SeminarViewModel() { Datum = DateTime.Now }; noviSeminar.Zaposlenici = new SelectList(zaposlenici, "IdZaposlenik", "Ime"); return(View(noviSeminar)); }
public async Task <ActionResult> Search(string key) { SeminarViewModel model = new SeminarViewModel(); var found = await serviceSeminar.SearchAsync(key); if (found.Count() == 0) { throw new ArgumentException("Nažalost unjeli ste netočne podatke :( "); } @ViewBag.Key = key; model.seminar = found; return(View("Index", model)); }
public async Task <ActionResult> Add(SeminarViewModel seminarViewModel) { try { await seminarService.AddAsync(mapper.Map <SeminarDTO>(seminarViewModel)); return(RedirectToAction(nameof(Seminar))); } catch (Exception ex) { var test = ex; return(View()); } }
public ActionResult Edit(int id) { var seminar = LoadSeminar(id); if (seminar == null) { ErrorMessages = string.Format(Messages.NotFound, "Seminar", id); return(this.RedirectToAction(a => a.Index())); } var viewModel = SeminarViewModel.Create(Repository, seminar.Site, seminar); return(View(viewModel)); }
public async Task Edit_updates_Seminar_with_correct_properties() { var s = Context.Seminars.FirstOrDefault(x => x.SeminarId == 1); s.Name = "Effects"; s.Description = "Learn about effects"; var seminarView = new SeminarViewModel(s, "http://completevocaltraining.nl") { CheckList = new List <CheckedId>() }; await Controller.Edit(1, seminarView); Context.Seminars.FirstOrDefault(x => x.SeminarId == 1).Should().BeEquivalentTo(s); }
// GET: Seminar/CreateForKolegij public ActionResult CreateForKolegij(int id) { IEnumerable <Seminar> seminariTrazenogKolegija = db.Seminar .Where(s => s.KolegijId == id); Seminar seminar = new Seminar { KolegijId = id }; SeminarViewModel seminarViewModel = new SeminarViewModel { seminar = seminar, seminariKolegija = seminariTrazenogKolegija.ToList() }; return(View(seminarViewModel)); }
public async Task Edit_returns_Redirect_to_Index_if_concurrencyException_occurs() { var s = await Context.Seminars.FirstOrDefaultAsync(x => x.SeminarId == 1); var days = await Context.Days.ToListAsync(); var seminarView = new SeminarViewModel(s, days); Context.Remove(s); await Context.SaveChangesAsync(); var result = await Controller.Edit(1, seminarView); result.As <RedirectToActionResult>().ActionName.Should().Match("Index"); }
public async Task Edit_updates_Seminar_with_correct_SeminarDays() { var s = Context.Seminars.FirstOrDefault(x => x.SeminarId == 1); var days = await Context.Days.ToListAsync(); var seminarView = new SeminarViewModel(s, days, "", "http://completevocaltraining.nl"); seminarView.CheckList[5].IsSelected = false; seminarView.CheckList[4].IsSelected = false; seminarView.CheckList[3].IsSelected = true; await Controller.Edit(1, seminarView); Context.Seminars.FirstOrDefault(x => x.SeminarId == 1)?.SeminarDays.Should() .HaveCount(1).And.Contain(x => x.Day.Name == "Day3"); }
public ActionResult Seminari(string pretraga, bool?popunjenost, bool?objava) { List <Seminar> seminari = new List <Seminar>(); List <SeminarViewModel> seminariViewModel = new List <SeminarViewModel>(); using (ApplicationDbContext _db = new ApplicationDbContext()) { if (pretraga == null || pretraga == "") { seminari = _db.Seminar.ToList(); } else { seminari = _db.Seminar.Where(x => x.Naziv.ToLower().Contains(pretraga.ToLower())).ToList(); } if (popunjenost != null) { seminari = seminari.Where(x => x.Popunjen == popunjenost).ToList(); } if (objava != null) { seminari = seminari.Where(x => x.Objava == objava).ToList(); } foreach (var item in seminari) { SeminarViewModel seminarViewModel = new SeminarViewModel(); seminarViewModel.IdSeminar = item.IdSeminar; seminarViewModel.Objava = item.Objava; seminarViewModel.Naziv = item.Naziv; seminarViewModel.Opis = item.Opis; seminarViewModel.Datum = item.Datum; seminarViewModel.MaxBrojPolaznika = item.MaxBrojPolaznika; seminarViewModel.Popunjen = item.Popunjen; seminarViewModel.UkupanBrojPredbiljezbi = item.Predbiljezbe.Count(); //dodajemo ukupan broj predbilježbi i šaljemo na popis seminara seminarViewModel.BrojOdobrenihPredbiljezbi = item.Predbiljezbe.Count(m => m.StatusPredbiljezbe == EnumStatusPredbiljezbe.Prihvacena); //dodajemo broj odobrenih predbilježbi i šaljemo na popis seminara seminarViewModel.BrojNeobradjenihPredbiljezbi = item.Predbiljezbe.Count(m => m.StatusPredbiljezbe == EnumStatusPredbiljezbe.Neobradjena); //dodajemo broj neobrađenih predbilježbi i šaljemo na popis seminara seminariViewModel.Add(seminarViewModel); } } return(View(seminariViewModel)); }
public IActionResult Edit(int id) { var seminar = repository.Seminars.ById(id); var obj = SeminarViewModel.Convert(seminar); obj.Attendees = repository.Attendees.Get(seminar.ID); ViewBag.Persons = repository.Persons.All(); if (obj != null) { return(View("Edit", obj)); } else { return(NotFound()); } }
public ActionResult Details(int?id) { var seminar = LoadSeminar(id); if (seminar == null) { ErrorMessages = string.Format(Messages.NotFound, "Seminar", id); return(this.RedirectToAction(a => a.Index())); } var viewModel = SeminarViewModel.Create(Repository, seminar.Site, seminar); viewModel.IsCurrent = SiteService.GetLatestSeminar(Site).Id == seminar.Id; viewModel.DisplayPeople = _personService.GetDisplayPeopleForSeminar(seminar.Id, Site); return(View(viewModel)); }
public async Task Edit_returns_View_if_modelstate_not_valid() { var controller = Controller; controller.ViewData.ModelState.AddModelError("key", "some error"); var seminarView = new SeminarViewModel { Seminar = new Seminar() { SeminarId = 1 }, CheckList = new List <CheckedId>() }; var result = await controller.Edit(1, seminarView); result.Should().BeOfType <ViewResult>(); }
public async Task AddSeminarAsync(SeminarViewModel model) { await AddAsync(model.Seminar); foreach (var item in model.CheckList) { if (item.IsSelected) { SeminarDay sd = new SeminarDay() { SeminarId = model.Seminar.SeminarId, DayId = item.Id }; _context.Add(sd); } } await _context.SaveChangesAsync(); }
public ActionResult Create(SeminarViewModel noviSeminar) { Seminar seminar = new Seminar(); seminar.IdSeminar = 0; seminar.Datum = noviSeminar.Datum; seminar.IdZaposlenik = noviSeminar.SelectedZaposlenikId; seminar.Naziv = noviSeminar.Naziv; seminar.Opis = noviSeminar.Opis; seminar.Popunjen = noviSeminar.Popunjen; if (ModelState.IsValid) { _db.Seminars.Add(seminar); _db.SaveChanges(); } return(RedirectToAction("SeminariEdit")); }
// GET: Seminari public async Task <ActionResult> Index(int page = 1) { SeminarViewModel model = new SeminarViewModel(); var all = await serviceSeminar.GetAllAsync(); var checkMe = all.OrderByDescending(p => p.Datum).Skip((page - 1) * pageSize).Take(pageSize); model.seminar = checkMe; model.pagingInfo = new PagingInfo() { TotalItems = all.Count(), ItemPerPage = pageSize, CurrentPage = page }; return(View(model)); }