public PachetGetModel Create(PachetPostModel pachetModel) { Pachet toAdd = PachetPostModel.ToPachet(pachetModel); context.Pachete.Add(toAdd); context.SaveChanges(); return(PachetGetModel.FromPachet(toAdd)); }
public Pachet Create(PachetPostModel pachetPostModel) { Pachet toAdd = PachetPostModel.ToPachet(pachetPostModel); context.Pachets.Add(toAdd); context.SaveChanges(); return(toAdd); }
//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); }
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)); }