Ejemplo n.º 1
0
 public ViewActivity GetActivity(int activityId)
 {
     ViewActivity viewActivity = new ViewActivity();
     using (OnATripEntities tr = new OnATripEntities())
     {
         var dbActivity = (from a in tr.Activities where a.ActivityID == activityId select a).FirstOrDefault();
         Mapper.Map(dbActivity, viewActivity);
     }
     return viewActivity;
 }
Ejemplo n.º 2
0
 public ViewActivity CreateActivity(ViewActivity viewActivity,int id)
 {
     // nacteni spravneho tripID ktere se overi v controlleru ze uzivatel je
     // vlastnikem tohoto vyletu
     viewActivity.TripID = id;
     using (OnATripEntities tr = new OnATripEntities())
     {
         Activity dbActivity = tr.Activities.Add(Mapper.Map<Activity>(viewActivity));
         var point = string.Format("POINT({1} {0})", viewActivity.gps.lat, viewActivity.gps.lon);
         dbActivity.GPS = System.Data.Entity.Spatial.DbGeography.FromText(point);
         tr.SaveChanges();
         viewActivity.ActivityID = dbActivity.ActivityID;
     }
     return viewActivity;
 }
Ejemplo n.º 3
0
        public ViewActivity UpdateActivity(ViewActivity viewActivity, int id)
        {

            using (OnATripEntities tr = new OnATripEntities())
            {
                Activity dbActivity = tr.Activities.Where(act => act.ActivityID == id).Select(act => act).FirstOrDefault();
                tr.ActivityActivityTypeMaps.RemoveRange(tr.ActivityActivityTypeMaps.Where(at => at.ActivityID == id));
                tr.SaveChanges();
                // odstranim z viewActivity objekty activityType, aby se znovu nepridaly do activityType
                foreach (var at in viewActivity.activityActivityTypeMaps)
                {
                    at.activityType = null;
                }

                Mapper.Map(viewActivity, dbActivity);
                dbActivity.ActivityID = id;
                var point = string.Format("POINT({1} {0})", viewActivity.gps.lat, viewActivity.gps.lon);
                dbActivity.GPS = System.Data.Entity.Spatial.DbGeography.FromText(point);
                tr.SaveChanges();
            }
            return viewActivity;
        }
Ejemplo n.º 4
0
 public ViewActivity Update(ViewActivity activity)
 {
     ICollection<ViewActivity> activities = new HashSet<ViewActivity>();
     using (OnATripEntities tr = new OnATripEntities())
     {
         Activity activityDb = tr.Activities.Where(a => a.ActivityID == activity.ActivityID).Select(a => a).FirstOrDefault();
         Mapper.Map(activity, activityDb);
         //tr.Entry(u1).State = System.Data.Entity.EntityState.Modified;
         tr.SaveChanges();
     }
     return activity;
 }
Ejemplo n.º 5
0
 public ViewActivity UpdateActivity(ViewActivity activity, int id)
 {
     // id = activityId
     return activityRepo.UpdateActivity(activity, id);
 }
Ejemplo n.º 6
0
 public ViewActivity CreateActivity(ViewActivity activity, int id)
 {
     // id = tripId
     return activityRepo.CreateActivity(activity,id);
 }