예제 #1
0
        public PachetGetModel Create(PachetPostModel pachetModel)
        {
            Pachet toAdd = PachetPostModel.ToPachet(pachetModel);

            context.Pachete.Add(toAdd);
            context.SaveChanges();
            return(PachetGetModel.FromPachet(toAdd));
        }
예제 #2
0
        public Pachet Create(PachetPostModel pachetPostModel)
        {
            Pachet toAdd = PachetPostModel.ToPachet(pachetPostModel);

            context.Pachets.Add(toAdd);
            context.SaveChanges();
            return(toAdd);
        }
예제 #3
0
        //acum mutam logica din Controller pe Service.
        //Nu il eliminam dar Controller-ul va apela Service si nu va mai apela UI-ul Service-ul

        public Pachet Create(PachetPostModel pachet, User addedBy)
        {
            Pachet toAdd = PachetPostModel.ToPachet(pachet);

            toAdd.Owner = addedBy;
            context.Pachete.Add(toAdd);
            context.SaveChanges();
            return(toAdd);
        }
예제 #4
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));
        }
예제 #5
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));
        }