예제 #1
0
        public EventDto UpdateEvent(EventDto dto)
        {
            try
            {
                //##### Manual Create a new Event
                var Adrress         = new Address(dto.Street, dto.Number, dto.Neigborhood, dto.City, dto.State, dto.Country, dto.ZipCode);
                var maintenanceDate = new MaintenanceDate(dto.RegisterDate, dto.LastUpdateDate);
                var activater       = new Activater(dto.Active);

                var Event = new Event(dto.Id.Value, Adrress, dto.DateEvent, dto.Theme, dto.Capacity, maintenanceDate, activater);

                var LotRemove = _uow.LotRepository.Get(a => !dto.Lots.Select(c => c.Id).Contains(a.Id) && a.EventId == dto.Id);
                var LotAdd    = new List <Lot>();
                var LotUpdate = new List <Lot>();

                foreach (var LotIn in dto.Lots.Where(c => c.Id == 0))
                {
                    var bb = new Lot(null, LotIn.Description, LotIn.CurrentEvent, Event, new Activater(LotIn.Active));

                    AddNotifications(bb);

                    LotAdd.Add(bb);
                }

                foreach (var LotUp in dto.Lots.Where(c => c.Id != 0))
                {
                    var bb = new Lot(LotUp.Id, LotUp.Description, LotUp.CurrentEvent, Event, new Activater(LotUp.Active));
                    LotUpdate.Add(bb);

                    AddNotifications(bb);
                }

                AddNotifications(Event);
                if (Valid)
                {
                    _uow.EventRepository.Update(Event);
                    _uow.LotRepository.DeleteRange(LotRemove);
                    _uow.LotRepository.AddRange(LotAdd);
                    _uow.LotRepository.UpdateRange(LotUpdate);

                    _uow.Commit();
                }

                Event.AddLots(LotUpdate);
                Event.AddLots(LotAdd);

                return(_mapper.Map <EventDto>(Event));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public Event(int?id, Address address, DateTime?dateEvent, string theme, int capacity, MaintenanceDate maintenanceDate, Activater activater)
        {
            Id              = id;
            Address         = address;
            DateEvent       = dateEvent;
            Theme           = theme;
            Capacity        = capacity;
            _Lotes          = new List <Lot>();
            MaintenanceDate = maintenanceDate == null ? new MaintenanceDate(null, null) : maintenanceDate;
            Activater       = activater == null ? new Activater(null) : activater;

            AddNotifications(
                new Contract()
                .Requires()
                .IsLowerOrEqualsThan(1, Capacity, "Capacity", "A capacidade deve ser informada.")
                );

            AddNotifications(Address);
        }