示例#1
0
        public override async Task <string> Save(Theatre theatre)
        {
            TheatreDataModel theatreDataModel = null;

            if (!string.IsNullOrWhiteSpace(theatre.Id))
            {
                theatreDataModel = await _dbContext.Theatres.SingleOrDefaultAsync(x => x.Id == theatre.Id);
            }

            if (theatreDataModel == null)
            {
                theatreDataModel = new TheatreDataModel()
                {
                    Name     = theatre.Name,
                    Capacity = theatre.Capacity
                };
            }

            _dbContext.Theatres.Update(theatreDataModel);
            await _dbContext.SaveChangesAsync();

            await DispatchEvents(theatre);

            return(theatreDataModel.Id);
        }
        public static Theatre ToTheatreAggregate(this TheatreDataModel theatreDataModel)
        {
            if (theatreDataModel == null)
            {
                return(null);
            }

            var theatre = new Theatre(theatreDataModel.Id, theatreDataModel.Name, theatreDataModel.Capacity);

            return(theatre);
        }