Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public IEnumerable <PachetGetModel> GetAll()
 {
     return(context
            .Pachets
            .OrderByDescending(p => p.Cost)
            .Select(pachet => PachetGetModel.FromPachet(pachet)));
 }
Exemplo n.º 3
0
        public PachetGetModel Create(PachetPostModel pachetModel)
        {
            Pachet toAdd = PachetPostModel.ToPachet(pachetModel);

            context.Pachete.Add(toAdd);
            context.SaveChanges();
            return(PachetGetModel.FromPachet(toAdd));
        }
Exemplo n.º 4
0
        public PachetGetModel GetById(int id)
        {
            Pachet pachet = context
                            .Pachets
                            .AsNoTracking()
                            .FirstOrDefault(p => p.Id == id);

            return(PachetGetModel.FromPachet(pachet));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        //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)));
        }