public void Execute(ProjectionDto request)
        {
            var projection = Context.Projections.Find(request.Id);

            if (projection == null || projection.IsDeleted == true)
            {
                throw new EntityNotFoundException("Projection");
            }

            var query = Context.Projections.AsQueryable();

            query = query.Where(p => p.Id != request.Id);

            if (query.Any(p => p.DateBegin <= request.DateEnd && p.DateEnd >= request.DateEnd))
            {
                throw new EntityAlreadyHasAnEntryException("projction at that time.");
            }

            if (query.Any(p => p.DateEnd >= request.DateBegin && p.DateEnd <= request.DateEnd))
            {
                throw new EntityAlreadyHasAnEntryException("projection at that time.");
            }

            projection.DateBegin = request.DateBegin;
            projection.DateEnd   = request.DateEnd;
            projection.HallId    = request.HallId;
            projection.MovieId   = request.MovieId;

            Context.SaveChanges();
        }
Esempio n. 2
0
 public ActionResult Create(ProjectionDto dto)
 {
     if (!ModelState.IsValid)
     {
         TempData["error"] = "Check your input.";
         return(RedirectToAction(nameof(Create)));
     }
     try
     {
         executor.ExecuteCommand(addProjection, dto);
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityNotAllowedException)
     {
         return(RedirectToAction("PageNotFound", "Redirections"));
     }
     catch (EntityAlreadyHasAnEntryException e)
     {
         TempData["error"] = e.Message;
     }
     catch (EntityAlreadyExistsException e)
     {
         TempData["error"] = e.Message;
     }
     catch (Exception e)
     {
         TempData["error"] = e.Message;
     }
     return(RedirectToAction(nameof(Index)));
 }
        public void Execute(ProjectionDto request)
        {
            var query = Context.Projections.AsQueryable();

            query = query.Where(c => c.IsDeleted == false);
            query = query.Where(c => c.HallId == request.HallId);

            if (query.Any(p => p.DateBegin <= request.DateEnd && p.DateEnd >= request.DateEnd))
            {
                throw new EntityAlreadyHasAnEntryException("projection at that time.");
            }

            if (query.Any(p => p.DateEnd >= request.DateBegin && p.DateEnd <= request.DateEnd))
            {
                throw new EntityAlreadyHasAnEntryException("projection at that time.");
            }

            if (request.DateBegin >= request.DateEnd)
            {
                throw new Exception("Projection cannot end before it even starts.");
            }

            Context.Projections.Add(new Projection
            {
                DateBegin = request.DateBegin,
                DateEnd   = request.DateEnd,
                HallId    = request.HallId,
                MovieId   = request.MovieId
            });

            Context.SaveChanges();
        }
Esempio n. 4
0
        public async Task <IActionResult> ExploreAsync([FromQuery] RequestModel model)
        {
            var           projectionType = model.ProjectionName.GetTypeByContract();
            ProjectionDto result         = await _projectionExplorer.ExploreAsync(Urn.Parse(model.Id), projectionType).ConfigureAwait(false);

            return(new OkObjectResult(new ResponseResult <ProjectionDto>(result)));
        }
Esempio n. 5
0
        public async Task <IActionResult> Meta([FromQuery] RequestModel model)
        {
            IEnumerable <Assembly> loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => assembly.IsDynamic == false);
            Type metadata = loadedAssemblies
                            .SelectMany(assembly => assembly.GetLoadableTypes()
                                        .Where(x => typeof(IProjection).IsAssignableFrom(x))
                                        .Where(x => x.GetCustomAttributes(typeof(DataContractAttribute), false).Length > 0))
                            .Where(x => x.GetContractId() == model.ProjectionContractId)
                            .FirstOrDefault();

            if (metadata is null)
            {
                return(new BadRequestObjectResult(new ResponseResult <string>($"Projection with contract '{model.ProjectionContractId}' not found")));
            }

            var           id  = new ProjectionVersionManagerId(model.ProjectionContractId, context.Tenant);
            ProjectionDto dto = await _projectionExplorer.ExploreAsync(id, typeof(ProjectionVersionsHandler));

            var state = dto?.State as ProjectionVersionsHandlerState;

            var metaProjection = new ProjectionMeta()
            {
                ProjectionContractId = metadata.GetContractId(),
                ProjectionName       = metadata.Name,
                IsReplayable         = typeof(IAmEventSourcedProjection).IsAssignableFrom(metadata)
            };

            if (state is null)
            {
                metaProjection.Versions.Add(new ProjectionVersionDto()
                {
                    Status   = ProjectionStatus.NotPresent,
                    Hash     = projectionHasher.CalculateHash(typeof(ProjectionVersionsHandler)),
                    Revision = 0
                });
            }
            else
            {
                foreach (var ver in state.AllVersions)
                {
                    metaProjection.Versions.Add(new ProjectionVersionDto()
                    {
                        Hash     = ver.Hash,
                        Revision = ver.Revision,
                        Status   = ver.Status
                    });
                }
            }

            return(Ok(new ResponseResult <ProjectionMeta>(metaProjection)));
        }
        public void Execute(ProjectionDto request)
        {
            var projection = _context.Projections.Find(request.Id);

            if (projection == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Projection));
            }

            _validator.ValidateAndThrow(request);

            _mapper.Map(request, projection);

            _context.SaveChanges();
        }
        private ProjectionDto MapToDto(Projection projection)
        {
            if (projection == null)
            {
                return(null);
            }

            var dto = new ProjectionDto();

            dto.Id                  = projection.Id;
            dto.MovieId             = projection.MovieId;
            dto.RoomId              = projection.RoomId;
            dto.StartDate           = projection.StartDate;
            dto.AvailableSeatsCount = projection.AvailableSeatsCount;

            return(dto);
        }
Esempio n. 8
0
 public ActionResult Edit(int id, ProjectionDto dto)
 {
     try
     {
         dto.Id = id;
         executor.ExecuteCommand(editProjection, dto);
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityNotAllowedException)
     {
         return(RedirectToAction("PageNotFound", "Redirections"));
     }
     catch (EntityAlreadyExistsException e)
     {
         TempData["error"] = e.Message;
     }
     catch (Exception e)
     {
         TempData["error"] = e.Message;
     }
     return(RedirectToAction(nameof(Index)));
 }
 public IActionResult Put(int id, [FromBody] ProjectionDto dto, [FromServices] IEditProjectionCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(NoContent());
 }