I am building ParkingReservation in DDD, In short means that people can invite place and when the car get in the camera identify the model and update the status of the place.
I divided the model to three Bounded contexts:
The first is Reservation Context that include the following objects:
`public class Lot
{
public int ID { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
public List<Place> Places { get; set; }
}
public class Place
{
public int ID { get; set; }
public int FloorNumber { get; set; }
public int RowNumber { get; set; }
public int ParkingNumber { get; set; }
}
public class Car
{
public int ID { get; set; }
public string Model { get; set; }
}
public class Driver
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public int Age { get; set; }
public Gender Gender { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public bool AcceptAdsToMail { get; set; }
public byte[] PictureData { get; set; }
public DateTime RegistrationTime { get; set; }
public DriverStatuses DriverStatuses { get; set; }
}
public class Reservation
{
public int ID { get; set; }
public Driver Driver { get; set; }
public Car Car { get; set; }
public Place Place { get; set; }
public DateTime OrderTime { get; set; }
public DateTime ParkingStartTime { get; set; }
public DateTime ParkingEndTime { get; set; }
public ParkingStatuses ParkingStatus { get; set; }
}
public class ParkingHistory
{
public int ID { get; set; }
public Place Place { get; set; }
public Driver Driver { get; set; }
public Car Car { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}`
The Parking Lot has list of places
the Driver reserve place through the application
the saved place saved in the Reservation object and when the parking time
elapsed, new parkinghistory added to parkinghistories list that belong to driver and car so you can watch history per car or driver.
for this context of Reservation:
(1) Is it correct to put Driver and Reservation for the Aggregate Roots? or maybe Lot too?
(2) Place is entity or value object?
Thank you
The main goal of your use case is scheduling. You need to think about a consistency boundary around that idea. To avoid time slots overlapping for a place in a lot you will need to create a new abstraction for the purpose.
"PlaceInLotReservations" sounds as a good option as an value object to serve as a factory for a Reservation aggregate. In order to represent reality of how scheduling works you should feed that aggregate in the context of a day, so "PlaceInLotReservationsRepository" should has a "findByDate" method that collects all Reservations for a place in a given datetime.
So the semantics would be something like:
val placeInLotReservations = PlaceInLotReservationsRepository.findBy(datetime)
val reservation = placeInLotReservations.reserveFor(car, driver, startingTime, endingTime)
ReservationsRepository.save(reservation)
If there are lot of reservations in a place and so race conditions you can even make the VO smaller by passing in day quarters instead of a day for the initial look up.
BTW, can and driver are VOs in the context of the Reservation aggregate (they are not aggregates).
You can also have the history by querying the Reservation repository, you donĀ“t need ParkingHistory.
Hope it helps.
Related
I have created an AutoQuery function in my API with the use of the following code.
[Route("/cars/search")]
public class SearchCars : QueryDb<Car, CarDto>, IJoin<Car, Equipment, Colour, FuelType, Manufacturer>
{
public List<int> EquipmentIds { get; set; }
public List<int> ManufacturerIds { get; set; }
public List<int> ColourIds { get; set; }
}
The CarDto looks like this
public class CarDto
{
public int Id { get; set; }
public List<Equipment> Equipment { get; set; }
public Manufacturer Manufacturer { get; set; }
public int ManufactorId { get; set; }
public FuelType FuelType { get; set; }
public int FuelTypeId { get; set; }
public byte[] ProfileImage { get; set; }
}
I was wondering if there are any specific values the IJoin looks for, because when I try to use this I get "Could not infer relationship between Car and Equipment"
Car looks like this.
[AutoIncrement]
public int Id { get; set; }
public int FuelTypeId { get; set; }
[Required]
public List<Equipment> Equipment { get; set; }
[Required]
public List<int> EquipmentIds { get; set; }
[Required]
public byte[] ProfileImage { get; set; }
Equipment looks like this.
[AutoIncrement]
public int Id { get; set; }
public EquipmentType EquipmentType { get; set; }
[Required]
public int EquipmentTypeId { get; set; }
[Required]
public string Name { get; set; }
I realise that there would require alot of magic knowing that EquipmentIds is a list of Ids that it should check for in the Equipment table, but since everything else with ServiceStack is magic, I am giving it a try.
NB I have shortened some of the models because they are long and contains lots of information which is not needed in this case.
Any joins in AutoQuery need to follow OrmLite's Reference Conventions.
I model three entities in the auto industry as following:
public class Manufacturer
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Model> Models { get; set; }
public ACManufacturer()
{
AutoCareModels = new List<ACModel>();
}
}
public class Model
{
public int Id { get; set; }
public string Name { get; set; }
public int NumberOfSeats { get; set; }
public Manufacturer Manufacturer { get; set; }
public ICollection<ManufacturedYear> ManufacturedYears { get; set; }
public Model()
{
ManufacturedYears = new List<ManufacturedYear>();
}
}
public class ManufacturedYear
{
public int Id { get; set; }
public int ProductionYear { get; set; }
public Model Model { get; set; }
}
Please tell me how to choose aggregate root or the differente way to model three entities
Thank you every much
Answer depends on what you do with these models. What is your app doing? If 10 users are updating data in this app - how can they divide their work? What are transaction boundaries?
If those 10 users are usually working with 10 different models, your screens are organized around models, then Model is your aggregate root.
I am new to MVC and i think someone answered this question before , so i apologize for re-posting it.
I've been a form based programmers for years , and now i am working on an MVC project for the first time, last 3 weeks i read a lot of books, articles, tutorials and watched a lot of videos about MVC.
Here is my question:
- I have 3 tables: Tasks, Customer and Employee
Each task has 1 customer and one employee assigned to it. I generated the Tasks table from an existing table i have on a SQL DB , but i followed "Code-First" to create the employee and Customer tables. I am not sure if i did the right relationships between those table. What i want to do is to display all tasks + the userNAME + CustomerName instead of UserID and CustomerID.
Here are my models:
Tasks:
public partial class Tasks
{
public string TaskID { get; set; }
public string Name { get; set; }
public System.DateTime StartDate { get; set; }
public Nullable<System.DateTime> DueDate { get; set; }
public Nullable<int> Complete { get; set; }
public string Description { get; set; }
public Nullable<int> Priority { get; set; }
public string Status { get; set; }
public Nullable<System.DateTime> AssignementDate { get; set; }
public Nullable<System.DateTime> CreationDate { get; set; }
[ForeignKey ("Employee")]
public string EmployeeID { get; set; }
public virtual ApplicationUser _User { get; set; }
[ForeignKey("Customer")]
public string CustomerID { get; set; }
public virtual CustomerModel _Customer { get; set; }
}
Customer:
public class CustomerModel
{
[Key]
public String ID { get; set; }
public String Number { get; set; }
}
Employee
public class EmployeeModel
{
[Key]
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Also How to access the employee first name from my Tasks controller.
Last question: is it ok to mix between models (Some code-first and some DB-first) Or should i follow one pattern.
Thanks a lot
You can use both pattern, but I recommend you my approach that you use CodeFirst, create entites to store data and viewmodels to display data:
public class Task
{
public int TaskID { get; set; }
//your other properties here...
public int EmployeeId { get; set; }
public int UserId { get; set; }
public int CustomerId { get; set; }
}
And in client lawyer, create ViewModel for Task model:
public class TaskViewModel
{
public Task Task { get; set; }
public EmployeeModel Employee { get; set; }
public ApplicationUser User { get; set; }
public CustomerModel Customer { get; set; }
}
In your GetTask() (Or LoadTasks()) method fill this view model:
public TaskViewModel GetTask(int id)
{
TaskViewModel model = new TaskViewModel();
model.Task = _db.GetTaskById(id);
model.Employee = _db.GetEmployeeById(model.Task.EmployeeId);
model.User = _db.GetUserById(model.Task.UserId);
model.Customer = _db.GetCustomerById(model.Task.CustomerId);
return model;
}
And now, you can get all data you want related to a task:
TaskId, TaskName, Created user's name + surname, Employee's name surname, Custemer's name + surname etc..
I have a problem with devising a many to many relationship in code first. EF is creating the Junction table and associating the Fk's as I would expect, however when i try to access the User's MailingList collection, there are no entries.
I've implemented test data on Initialise via Seeding, the data is al present in the database.
I think the problem lies with the constructors for Users and MailingLists, but I'm uncertain. I want to be able to navigate the navigational property of User.MailingLists.
var user = db.Users.Find(1);
Console.WriteLine("{0}", user.EmailAddress); //This is Fine
Console.WriteLine("{0}", user.Address.PostCode); /This is Fine
foreach (MailingList ml in user.MailingLists) // this is 0
{
Console.WriteLine("{0}", ml.Name);
}
My model is below:-
public class User : IEntityBase
{
public User()
{
MailingLists = new List<MailingList>();
}
public int Id { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public string EmailAddress { get; set; }
public DateTime? DateLastUpdated { get; set; }
public DateTime DateCreated { get; set; }
public bool IsDeleted { get; set; }
public virtual Address Address { get; set; }
public ICollection<MailingList> MailingLists { get; set; }
}
public class MailingList : IEntityBase
{
public MailingList()
{
Users = new List<User>();
}
public int Id { get; set; }
public string Name { get; set; }
public DateTime? DateLastUpdated { get; set; }
public DateTime DateCreated { get; set; }
public bool IsDeleted { get; set; }
public ICollection<User> Users { get; set; }
}
public class Address : IEntityBase
{
public int Id { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string AddressLine3 { get; set; }
public string City { get; set; }
public string County { get; set; }
public string PostCode { get; set; }
public DateTime? DateLastUpdated { get; set; }
public DateTime DateCreated { get; set; }
public bool IsDeleted { get; set; }
}
Any suggestions welcome.
You are neither eager loading the MailingList entries with the query, nor fulfulling the requirements for a lazy loading proxy so there is no way EF can populate the collection.
To allow lazy loading, change the MailingList property to be virtual to allow the EF proxy to override it.
To use eager loading, use Include() (an extension method in System.Data.Entity) in the query to specify that the MailingList should be loaded.
It's the first time I use Subsonic.
Let say I have those classes :
public class Store
{
public int Id { get; set; }
public String Name { get; set; }
}
public class Employee
{
public int Id { get; set; }
public String Name { get; set; }
}
An employee is related to a store with is hired date. This means that in the database I will have a middle table With StoreId, EmployeeId, StartDate, EndDate
UPDATE
An employee can work to the StoreA from 2009-01-01 to 2009-04-04 and work for StoreB from 2009-04-05 to ... And I don't want that my data table repeat all the information of my employee each time an employee change the store he working for. In this example employee have only a name, but lets say an employee got 10 property (adress, age, gender ...)
How could I achieve that ?
Based on your comment and the updated question it looks like you want something like the following:
public class Store
{
public int Id { get; set; }
public String Name { get; set; }
}
public class StoreEmployee
{
public int Id { get; set; }
public Employee Employee { get; set; }
public Store Store { get; set; }
public DateTime HiredDate { get; set; }
}
public class Employee
{
public int Id { get; set; }
public String Name { get; set; }
}
You'll actually need a many-to-many relationship which will join an Employee record to a Store Record, with a payload of Start and End Dates.
The Objects will look like this:
public class Store
{
public int Id { get; set; }
public String Name { get; set; }
}
public class Employee
{
public int Id { get; set; }
public String Name { get; set; }
public IList<EmploymentTerm> EmploymentTerms { get; set; }
}
public class EmploymentTerm
{
public int Id { get; set; }
public Store Store { get; set; }
public Employee Employee { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
}
Did this freehand so there could be a couple errors.