00001 using System; 00002 using System.Collections.Generic; 00003 using System.Text; 00004 using Foodolini.Database; 00005 00006 namespace Foodolini.BusinessLogic 00007 { 00011 public class SportsActivity 00012 { 00013 private bool modified = true; 00014 private SportsActivityRow row; 00015 00025 public SportsActivity(string name, double METS){ 00026 this.row = new SportsActivityRow(); 00027 this.row.Name = name; 00028 this.row.METS = METS; 00029 this.modified = true; 00030 } 00031 00038 internal SportsActivity(long activityId){ 00039 this.row = Settings.Repo.SingleWhere<SportsActivityRow>("SportsActivityRowId = @0", activityId); 00040 if(row == null) 00041 throw new Exception("The SportsActivity does not exist."); 00042 this.modified = false; 00043 } 00044 00051 internal SportsActivity(SportsActivityRow row){ 00052 this.row = row; 00053 this.modified = row.SportsActivityRowId != 0; 00054 } 00055 00056 00060 internal long Id { 00061 get{ 00062 return this.row.SportsActivityRowId; 00063 } 00064 } 00065 00069 public string Name 00070 { 00071 get{ 00072 return this.row.Name; 00073 } 00074 set{ 00075 this.modified = true; 00076 this.row.Name = value; 00077 } 00078 } 00079 00083 public double METS 00084 { 00085 get{ 00086 return this.row.METS; 00087 } 00088 set{ 00089 this.modified = true; 00090 this.row.METS = value; 00091 } 00092 } 00093 00097 public void Save(){ 00098 if(this.row.SportsActivityRowId == 0) 00099 Settings.Repo.Add<SportsActivityRow>(this.row); 00100 else if(this.modified) 00101 Settings.Repo.Update<SportsActivityRow>(this.row); 00102 this.modified = false; 00103 } 00104 00108 public void Delete(){ 00109 if(this.row.SportsActivityRowId != 0) 00110 Settings.Repo.Delete<SportsActivityRow>(this.row); 00111 this.modified = true; 00112 } 00113 00118 public static IEnumerable<SportsActivity> ListActivities(){ 00119 foreach(var act in Settings.Repo.All<SportsActivityRow>()) 00120 yield return new SportsActivity(act); 00121 } 00122 } 00123 }