public PaginatedList <PachetGetModel> GetAll(int page) { //IQueryable<Movie> result = context.Movies.Include(f => f.Comments); IQueryable <Pachet> result = context .Pachete .OrderBy(f => f.Id) // .Include(c => c.Comments) .OrderByDescending(m => m.Cost); PaginatedList <PachetGetModel> paginatedResult = new PaginatedList <PachetGetModel>(); paginatedResult.CurrentPage = page; //if (from != null) //{ // result = result.Where(f => f.Date >= from); //} //if (to != null) //{ // result = result.Where(f => f.Date <= to); //} paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <PachetGetModel> .EntriesPerPage + 1; result = result .Skip((page - 1) * PaginatedList <PachetGetModel> .EntriesPerPage) .Take(PaginatedList <PachetGetModel> .EntriesPerPage); paginatedResult.Entries = result.Select(m => PachetGetModel.FromPachet(m)).ToList(); return(paginatedResult); }
public IEnumerable <PachetGetModel> GetAll() { return(context .Pachets .OrderByDescending(p => p.Cost) .Select(pachet => PachetGetModel.FromPachet(pachet))); }
public PachetGetModel Create(PachetPostModel pachetModel) { Pachet toAdd = PachetPostModel.ToPachet(pachetModel); context.Pachete.Add(toAdd); context.SaveChanges(); return(PachetGetModel.FromPachet(toAdd)); }
public PachetGetModel GetById(int id) { Pachet pachet = context .Pachets .AsNoTracking() .FirstOrDefault(p => p.Id == id); return(PachetGetModel.FromPachet(pachet)); }
public PachetGetModel Delete(int id) { var existing = context.Pachete .FirstOrDefault(p => p.Id == id); if (existing == null) { return(null); } context.Pachete.Remove(existing); context.SaveChanges(); return(PachetGetModel.FromPachet(existing)); }
public PachetGetModel Upsert(int id, PachetPostModel pachetPostModel) { var existing = context.Pachets.AsNoTracking().FirstOrDefault(pachet => pachet.Id == id); if (existing == null) { Pachet toAdd = PachetPostModel.ToPachet(pachetPostModel); context.Pachets.Add(toAdd); context.SaveChanges(); return(PachetGetModel.FromPachet(toAdd)); } Pachet Update = PachetPostModel.ToPachet(pachetPostModel); Update.Id = id; context.Pachets.Update(Update); context.SaveChanges(); return(PachetGetModel.FromPachet(Update)); }
public PachetGetModel Upsert(int id, PachetPostModel pachetModel) { var existing = context.Pachete.AsNoTracking().FirstOrDefault(p => p.Id == id); if (existing == null) { Pachet toAdd = PachetPostModel.ToPachet(pachetModel); context.Pachete.Add(toAdd); context.SaveChanges(); return(PachetGetModel.FromPachet(toAdd)); } //context.Entry(existing).State = EntityState.Detached; Pachet toUpdate = PachetPostModel.ToPachet(pachetModel); toUpdate.Id = id; context.Pachete.Update(toUpdate); context.SaveChanges(); return(PachetGetModel.FromPachet(toUpdate)); }
//public IEnumerable<PachetGetModel> GetAll() //{ // return context.Pachete.Select(pachet => PachetGetModel.FromPachet(pachet)); //} public IEnumerable <PachetGetModel> GetByExpeditor(string expeditor) { IQueryable <Pachet> result = context.Pachete.Where(p => p.DenumireExpeditor == expeditor); return(result.Select(p => PachetGetModel.FromPachet(p))); }