public void BindPonuda() { SuspendLayout(); Controls.Clear(); for (int i = 0; i < PonudaViewModel.Count(); i++) { var newCtl = new PonudaItem(PonudaViewModel.ElementAt(i)); SetCardControlLayout(newCtl, i); Controls.Add(newCtl); newCtl.DataBind(); } ResumeLayout(); }
public ActionResult PrikaziIzbrisane() { PonudaViewModel Model = new PonudaViewModel(); Model.Ponude = ctx.Ponude .Where(x => x.IsDeleted) .Select(x => new PonudaViewModel.PonudaInfo() { Id = x.Id, NazivPonude = x.NazivPonude, VaziOd = x.VaziOd, VaziDo = x.VaziDo, Aktivna = x.Aktivna, restoranId = x.RestoranId }).ToList(); return(View("PrikaziIzbrisane", Model)); }
public async Task <IActionResult> Edit(PonudaViewModel model, int page = 1, int sort = 1, bool ascending = true) { ViewBag.Page = page; ViewBag.Sort = sort; ViewBag.Ascending = ascending; if (ModelState.IsValid) { var ponuda = await ctx.Ponuda .Include(d => d.PonDokumentis) .Where(d => d.PonudaId == model.PonudaId) .FirstOrDefaultAsync(); if (ponuda == null) { return(NotFound("Ne postoji ponuda s id-om: " + model.PonudaId)); } /* if (position.HasValue) * { * page = 1 + position.Value / appData.PageSize; * await SetPreviousAndNext(position.Value, filter, sort, ascending); * } */ ponuda.PonudaId = model.PonudaId; ponuda.EvidBrojNatječaj = model.EvidBrojNatječaj; ponuda.Text = model.Text; ponuda.Naslov = model.Naslov; ponuda.OibPonuditelj = model.OibPonuditelj; List <int> DoksId = model.doks .Where(s => s.DokumentId > 0) .Select(s => s.DokumentId) .ToList(); //izbaci sve koje su nisu više u modelu ctx.RemoveRange(ponuda.PonDokumentis.Where(s => !DoksId.Contains(s.DokumentId))); ctx.RemoveRange(ctx.Dokuments.Where(s => !DoksId.Contains(s.DokumentId))); foreach (var dokument1 in model.doks) { //ažuriraj postojeće i dodaj nove Dokument noviDokkument; // potpuno nova ili dohvaćena ona koju treba izmijeniti if (dokument1.DokumentId > 0) { noviDokkument = ponuda.PonDokumentis.First(s => s.DokumentId == dokument1.DokumentId).Dokument; } else { noviDokkument = new Dokument(); ctx.Add(noviDokkument); } noviDokkument.DokumentId = dokument1.DokumentId; noviDokkument.Naslov = dokument1.Naslov; noviDokkument.Vrsta = dokument1.Vrsta; noviDokkument.Blob = dokument1.Blob; noviDokkument.PonudaId = dokument1.PonudaId; noviDokkument.DatumPredaje = dokument1.DatumPredaje; } try { await ctx.SaveChangesAsync(); TempData[Constants.Message] = $"Ponuda {ponuda.PonudaId} uspješno ažuriran."; TempData[Constants.ErrorOccurred] = false; return(RedirectToAction(nameof(Edit), new { id = ponuda.PonudaId, page, sort, ascending })); } catch (Exception exc) { ModelState.AddModelError(string.Empty, exc.CompleteExceptionMessage()); return(View(model)); } } else { return(View(model)); } }