| 1 | '''User.cs''' |
| 2 | {{{ |
| 3 | #!c# |
| 4 | using NakedObjects; |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.ComponentModel.DataAnnotations; |
| 8 | using System.Linq; |
| 9 | using System.Text; |
| 10 | using System.Threading.Tasks; |
| 11 | |
| 12 | namespace CoDBIS_NakedObjects |
| 13 | { |
| 14 | public class User |
| 15 | { |
| 16 | public override string ToString() |
| 17 | { |
| 18 | return Name; |
| 19 | } |
| 20 | |
| 21 | |
| 22 | [Hidden] |
| 23 | public virtual int Id { get; set; } |
| 24 | |
| 25 | [StringLength (50)] |
| 26 | public virtual string Name { get; set; } |
| 27 | |
| 28 | |
| 29 | public virtual string Gender { get; set; } |
| 30 | |
| 31 | |
| 32 | public virtual string PlaceOfBirth { get; set; } |
| 33 | |
| 34 | [Mask("d")] |
| 35 | public virtual DateTime DateOfBirth { get; set; } |
| 36 | |
| 37 | |
| 38 | public virtual string Email { get; set; } |
| 39 | |
| 40 | |
| 41 | public virtual string Employer { get; set; } |
| 42 | |
| 43 | |
| 44 | public virtual string Position { get; set; } |
| 45 | |
| 46 | public IDomainObjectContainer Container { set; protected get; } |
| 47 | |
| 48 | |
| 49 | #region AddActivity (collection) |
| 50 | private ICollection<AddUserOnActivity> _AddActivity = new List<AddUserOnActivity>(); |
| 51 | |
| 52 | public virtual ICollection<AddUserOnActivity> AddActivity |
| 53 | { |
| 54 | get |
| 55 | { |
| 56 | return _AddActivity; |
| 57 | } |
| 58 | set |
| 59 | { |
| 60 | _AddActivity = value; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | public void AddToAddActivity(AddUserOnActivity value) |
| 65 | { |
| 66 | if (!(_AddActivity.Contains(value))) |
| 67 | { |
| 68 | _AddActivity.Add(value); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | public void RemoveFromAddActivity(AddUserOnActivity value) |
| 74 | { |
| 75 | if (_AddActivity.Contains(value)) |
| 76 | { |
| 77 | _AddActivity.Remove(value); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public IList<AddUserOnActivity> Choices0RemoveFromAddActivity() |
| 82 | { |
| 83 | return _AddActivity.ToList(); |
| 84 | } |
| 85 | #endregion |
| 86 | |
| 87 | public AddUserOnActivity CreateNewUserOnActivity() //CreateNewOrder od tip Order |
| 88 | { |
| 89 | |
| 90 | var order = Container.NewTransientInstance<AddUserOnActivity>(); |
| 91 | order.User = this; |
| 92 | return order; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | public AddUserOnActivity CreateNewAddUserOnActivity() |
| 99 | { |
| 100 | AddUserOnActivity obj = Container.NewTransientInstance<AddUserOnActivity>(); |
| 101 | |
| 102 | obj.User = this; |
| 103 | return obj; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | |
| 108 | } |
| 109 | } |
| 110 | }}} |
| 111 | |
| 112 | '''Activity.cs''' |
| 113 | {{{ |
| 114 | #!c# |
| 115 | using NakedObjects; |
| 116 | using System; |
| 117 | using System.Collections.Generic; |
| 118 | using System.ComponentModel.DataAnnotations; |
| 119 | using System.Linq; |
| 120 | using System.Text; |
| 121 | using System.Threading.Tasks; |
| 122 | |
| 123 | namespace CoDBIS_NakedObjects |
| 124 | { |
| 125 | public class Activity |
| 126 | { |
| 127 | public override string ToString() |
| 128 | { |
| 129 | return Name; |
| 130 | } |
| 131 | |
| 132 | [Hidden] |
| 133 | public virtual int Id { get; set; } |
| 134 | |
| 135 | |
| 136 | [StringLength (50), Title] |
| 137 | public virtual string Name { get; set; } |
| 138 | |
| 139 | |
| 140 | public virtual string Place { get; set; } |
| 141 | |
| 142 | // [Title, Mask("d")] |
| 143 | public virtual DateTime Date { get; set; } |
| 144 | |
| 145 | |
| 146 | public virtual string Category { get; set; } |
| 147 | |
| 148 | } |
| 149 | } |
| 150 | }}} |
| 151 | |
| 152 | '''Activityhistory.cs''' |
| 153 | {{{ |
| 154 | #!c# |
| 155 | using NakedObjects; |
| 156 | using System; |
| 157 | using System.Collections.Generic; |
| 158 | using System.ComponentModel; |
| 159 | using System.Linq; |
| 160 | using System.Text; |
| 161 | using System.Threading.Tasks; |
| 162 | |
| 163 | namespace CoDBIS_NakedObjects |
| 164 | { |
| 165 | public class ActivityHistory |
| 166 | { |
| 167 | |
| 168 | public override string ToString() |
| 169 | { |
| 170 | return Role.ToString() + " на " + Activity; |
| 171 | } |
| 172 | |
| 173 | [Hidden] |
| 174 | public virtual int Id { get; set; } |
| 175 | |
| 176 | [Hidden] |
| 177 | public virtual AddUserOnActivity AddUserOnActivity { get; set; } |
| 178 | |
| 179 | |
| 180 | public virtual Activity Activity { get; set; } |
| 181 | |
| 182 | [DefaultValue("")] |
| 183 | public virtual string Role { get; set; } |
| 184 | |
| 185 | } |
| 186 | } |
| 187 | }}} |
| 188 | |
| 189 | '''Adduseronactivity.cs''' |
| 190 | {{{ |
| 191 | #!c# |
| 192 | using NakedObjects; |
| 193 | using System; |
| 194 | using System.Collections.Generic; |
| 195 | using System.Linq; |
| 196 | using System.Text; |
| 197 | using System.Threading.Tasks; |
| 198 | |
| 199 | namespace CoDBIS_NakedObjects |
| 200 | { |
| 201 | public class AddUserOnActivity |
| 202 | { |
| 203 | |
| 204 | public override string ToString() |
| 205 | { |
| 206 | return User.ToString(); |
| 207 | } |
| 208 | |
| 209 | [Hidden] |
| 210 | public virtual int Id { get; set; } |
| 211 | |
| 212 | [Disabled] |
| 213 | public virtual User User { get; set; } |
| 214 | |
| 215 | |
| 216 | |
| 217 | #region History (collection) |
| 218 | private ICollection<ActivityHistory> _History = new List<ActivityHistory>(); |
| 219 | |
| 220 | public virtual ICollection<ActivityHistory> History |
| 221 | { |
| 222 | get |
| 223 | { |
| 224 | return _History; |
| 225 | } |
| 226 | set |
| 227 | { |
| 228 | _History = value; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | public void AddToHistory(ActivityHistory value) |
| 233 | { |
| 234 | if (!(_History.Contains(value))) |
| 235 | { |
| 236 | _History.Add(value); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | public void RemoveFromHistory(ActivityHistory value) |
| 241 | { |
| 242 | if (_History.Contains(value)) |
| 243 | { |
| 244 | _History.Remove(value); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | public IList<ActivityHistory> Choices0RemoveFromHistory() |
| 249 | { |
| 250 | return _History.ToList(); |
| 251 | } |
| 252 | #endregion |
| 253 | |
| 254 | |
| 255 | public IDomainObjectContainer Container { set; protected get; } |
| 256 | |
| 257 | |
| 258 | public ActivityHistory AddToHistory() |
| 259 | { |
| 260 | |
| 261 | var history = Container.NewTransientInstance<ActivityHistory>(); |
| 262 | history.AddUserOnActivity = this; |
| 263 | return history; |
| 264 | } |
| 265 | |
| 266 | |
| 267 | public ActivityHistory CreateNewActivityHistory() |
| 268 | { |
| 269 | ActivityHistory obj = Container.NewTransientInstance<ActivityHistory>(); |
| 270 | |
| 271 | obj.AddUserOnActivity = this; |
| 272 | return obj; |
| 273 | } |
| 274 | |
| 275 | |
| 276 | |
| 277 | } |
| 278 | } |
| 279 | }}} |
| 280 | |
| 281 | '''Mydbcontext.cs''' |
| 282 | {{{ |
| 283 | #!c# |
| 284 | using System; |
| 285 | using System.Collections.Generic; |
| 286 | using System.Data.Entity; |
| 287 | using System.Linq; |
| 288 | using System.Text; |
| 289 | using System.Threading.Tasks; |
| 290 | |
| 291 | namespace CoDBIS_NakedObjects |
| 292 | { |
| 293 | public class MyDbContext : DbContext |
| 294 | { |
| 295 | public MyDbContext(String name) : base(name) { } |
| 296 | public MyDbContext() { } |
| 297 | public DbSet<User> Users { get; set; } |
| 298 | |
| 299 | } |
| 300 | } |
| 301 | }}} |
| 302 | |
| 303 | '''Userrepository.cs''' |
| 304 | {{{ |
| 305 | #!c# |
| 306 | using NakedObjects; |
| 307 | using System; |
| 308 | using System.Collections.Generic; |
| 309 | using System.ComponentModel; |
| 310 | using System.Linq; |
| 311 | using System.Text; |
| 312 | using System.Threading.Tasks; |
| 313 | |
| 314 | namespace CoDBIS_NakedObjects |
| 315 | { |
| 316 | |
| 317 | [DisplayName("Users")] |
| 318 | public class UserRepository |
| 319 | { |
| 320 | |
| 321 | public IDomainObjectContainer Container { set; protected get; } |
| 322 | |
| 323 | public IQueryable<User> AllUsers() |
| 324 | { |
| 325 | return Container.Instances<User>(); |
| 326 | } |
| 327 | |
| 328 | |
| 329 | public User CreateNewUser() |
| 330 | { |
| 331 | User obj = Container.NewTransientInstance<User>(); |
| 332 | //set up any parameters |
| 333 | //Container.Persist(ref obj); |
| 334 | return obj; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | #region Find |
| 339 | public User Find(string searchString) |
| 340 | { |
| 341 | var query = from obj in Container.Instances<User>() |
| 342 | where obj.Name.ToUpper().Contains(searchString.ToUpper()) |
| 343 | select obj; |
| 344 | |
| 345 | return query.FirstOrDefault(); |
| 346 | //(If inheriting from AbsractFactoryAndRepository can use:) return SingleObjectWarnIfNoMatch(query); |
| 347 | } |
| 348 | #endregion |
| 349 | |
| 350 | |
| 351 | } |
| 352 | } |
| 353 | }}} |
| 354 | |
| 355 | |
| 356 | |
| 357 | '''Activityrepository.cs''' |
| 358 | {{{ |
| 359 | #!c# |
| 360 | using NakedObjects; |
| 361 | using System; |
| 362 | using System.Collections.Generic; |
| 363 | using System.ComponentModel; |
| 364 | using System.Linq; |
| 365 | using System.Text; |
| 366 | using System.Threading.Tasks; |
| 367 | |
| 368 | namespace CoDBIS_NakedObjects |
| 369 | { |
| 370 | [DisplayName("Activities")] |
| 371 | public class ActivityRepository |
| 372 | { |
| 373 | public IDomainObjectContainer Container { set; protected get; } |
| 374 | |
| 375 | |
| 376 | public IQueryable<Activity> AllActivitys() |
| 377 | { |
| 378 | return Container.Instances<Activity>(); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | public Activity CreateNewActivity() |
| 383 | { |
| 384 | Activity obj = Container.NewTransientInstance<Activity>(); |
| 385 | //set up any parameters |
| 386 | //Container.Persist(ref obj); |
| 387 | return obj; |
| 388 | } |
| 389 | |
| 390 | |
| 391 | #region Find |
| 392 | public Activity Find(string name ) |
| 393 | { |
| 394 | var query = from obj in Container.Instances<Activity>() |
| 395 | where obj.Name.ToUpper().Contains(name.ToUpper()) |
| 396 | select obj; |
| 397 | |
| 398 | return query.FirstOrDefault(); |
| 399 | //(If inheriting from AbsractFactoryAndRepository can use:) return SingleObjectWarnIfNoMatch(query); |
| 400 | } |
| 401 | #endregion |
| 402 | |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | }}} |
| 407 | |
| 408 | '''Runweb.cs''' |
| 409 | {{{ |
| 410 | #!c# |
| 411 | using CoDBIS_NakedObjects; |
| 412 | using NakedObjects.Boot; |
| 413 | using NakedObjects.Core.Context; |
| 414 | using NakedObjects.Core.NakedObjectsSystem; |
| 415 | using NakedObjects.EntityObjectStore; |
| 416 | using NakedObjects.Services; |
| 417 | using NakedObjects.Web.Mvc; |
| 418 | using NakedObjects.Web.Mvc.Helpers; |
| 419 | using System.Data.Entity; |
| 420 | using System.Data.Entity.Infrastructure; |
| 421 | |
| 422 | |
| 423 | namespace CoDBIS_MVC.App_Start { |
| 424 | public class RunWeb : RunMvc { |
| 425 | protected override NakedObjectsContext Context { |
| 426 | get { return HttpContextContext.CreateInstance(); } |
| 427 | } |
| 428 | |
| 429 | protected override IServicesInstaller MenuServices { |
| 430 | get { |
| 431 | return new ServicesInstaller( new UserRepository(), new ActivityRepository()); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | protected override IServicesInstaller ContributedActions { |
| 436 | get { return new ServicesInstaller(); } |
| 437 | } |
| 438 | |
| 439 | protected override IServicesInstaller SystemServices { |
| 440 | get { return new ServicesInstaller(new SimpleEncryptDecrypt()); } |
| 441 | } |
| 442 | |
| 443 | |
| 444 | // example functions that gets types for AssociateTypes below |
| 445 | //private static Type[] AdventureWorksTypes() { |
| 446 | // var allTypes = AppDomain.CurrentDomain.GetAssemblies().Single(a => a.GetName().Name == "AdventureWorksModel").GetTypes(); |
| 447 | // return allTypes.Where(t => t.BaseType == typeof(AWDomainObject) && !t.IsAbstract).ToArray(); |
| 448 | //} |
| 449 | // |
| 450 | //private static Type[] CodeFirstTypes() { |
| 451 | // return new[] {typeof(Class1), typeof(Class2)}; |
| 452 | //} |
| 453 | |
| 454 | protected override IObjectPersistorInstaller Persistor |
| 455 | { |
| 456 | get |
| 457 | { |
| 458 | Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); //For in-memory database |
| 459 | Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyDbContext>()); //Optional behaviour for CodeFirst |
| 460 | var installer = new EntityPersistorInstaller(); |
| 461 | |
| 462 | //installer.UsingEdmxContext("Model").AssociateTypes(AdventureWorksTypes); // for Model/Database First |
| 463 | installer.AddCodeFirstDbContextConstructor(() => new MyDbContext()); //For Code First |
| 464 | |
| 465 | return installer; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | public static void Run() { |
| 470 | new RunWeb().Start(); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | }}} |