Esempio n. 1
0
        public CarDTO AddNewCar(CarDTO dto)
        {
            var newCar = _carFactory.Create(dto);

            _uow.Cars.Add(newCar);
            _uow.SaveChanges();
            return(_carFactory.Create(newCar));
        }
Esempio n. 2
0
        public PersonDTO AddNewPerson(PersonDTO dto)
        {
            var newPerson = _personFactory.Create(dto);

            _uow.People.Add(newPerson);
            _uow.SaveChanges();
            return(_personFactory.Create(newPerson));
        }
Esempio n. 3
0
        //public IEnumerable<SiteDTO> FindCarsByLicensePlate(string licensePlate)
        //{
        //    if (String.IsNullOrEmpty(licensePlate)) return null;

        //    return _uow.Sites.All().Where(x => x.LicensePlate.Contains(licensePlate))
        //        .Select(car => _siteFactory.Create(car)).ToList();
        //}

        //public IEnumerable<SiteDTO> FindCarsByPersonId(int personId)
        //{
        //    return _uow.Sites.All().Where(x => x.PersonId == personId)
        //        .Select(car => _siteFactory.Create(car)).ToList();
        //}

        //public List<SiteDTO> FindCars(string licensePlate, int personId)
        //{
        //    List<Site> cars = new List<Site>();
        //    if (licensePlate != null)
        //    {
        //        cars = _uow.Sites.FindByLicensePlate(licensePlate);
        //    } else if (personId != 0)
        //    {
        //        cars = _uow.Sites.FindByPersonId(personId);
        //    }

        //    if (cars == null  || cars.Count == 0) return null;

        //    var carCollection = new List<SiteDTO>();

        //    foreach (var car in cars)
        //    {
        //        carCollection.Add(_siteFactory.Create(car));
        //    }

        //    return carCollection;
        //}

        public SiteDTO AddNewSite(SiteDTO dto)
        {
            var newSite = _siteFactory.Create(dto);

            _uow.Sites.Add(newSite);
            _uow.SaveChanges();
            return(_siteFactory.Create(newSite));
        }
Esempio n. 4
0
        public QuestionDTO CreateNewQuestion(QuestionDTO qdto)
        {
            var newQuestion = _questionFactory.Create(qdto);

            _uow.Questions.Add(newQuestion);
            _uow.SaveChanges();

            return(_questionFactory.Create(newQuestion));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="newEvent"></param>
 /// <returns></returns>
 public EventDTO AddNewEvent(EventDTO newEvent)
 {
     try
     {
         var e = _eventFactory.Transform(newEvent);
         _uow.Events.Add(e);
         _uow.SaveChanges();
         return(_eventFactory.Transform(_uow.Events.Find(e.EventId)));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
 public LocationDTO AddNewLocation(LocationDTO newLocation)
 {
     try
     {
         var l = _locationFactory.Transform(newLocation);
         _uow.Locations.Add(l);
         _uow.SaveChanges();
         return(_locationFactory.Transform(_uow.Locations.Find(l.LocationId)));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
 public EventTypeDTO AddNewEventType(EventTypeDTO newEventType)
 {
     try
     {
         var et = _eventTypeFactory.Transform(newEventType);
         _uow.EventTypes.Add(et);
         _uow.SaveChanges();
         return(_eventTypeFactory.Transform(et));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
Esempio n. 8
0
 public LocationTypeDTO AddNewLocationType(LocationTypeDTO newLocationType)
 {
     try
     {
         var lt = _locationTypeFactory.Transform(newLocationType);
         _uow.LocationTypes.Add(lt);
         _uow.SaveChanges();
         return(_locationTypeFactory.Transform(lt));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
 public PerformerDTO AddNewPerformer(PerformerDTO newPerformer)
 {
     try
     {
         var p = _performerFactory.Transform(newPerformer);
         _uow.Performers.Add(p);
         _uow.SaveChanges();
         return(_performerFactory.Transform(_uow.Performers.Find(p.PerformerId)));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
 public TicketTypeDTO AddNewTicketType(TicketTypeDTO newTicketType)
 {
     try
     {
         var tt = _ticketTypeFactory.Transform(newTicketType);
         _uow.TicketTypes.Add(tt);
         _uow.SaveChanges();
         return(_ticketTypeFactory.Transform(_uow.TicketTypes.Find(tt.TicketTypeId)));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
Esempio n. 11
0
 public PerformerTypeDTO AddNewPerformerType(PerformerTypeDTO newPerformerType)
 {
     try
     {
         var performerType = _performerTypeFactory.Transform(newPerformerType);
         _uow.PerformerTypes.Add(performerType);
         _uow.SaveChanges();
         return(_performerTypeFactory.Transform(performerType));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
 public PerformanceDTO AddNewPerformance(PerformanceDTO newPerformance)
 {
     try
     {
         var p = _performanceFactory.Transform(newPerformance);
         _uow.Performances.Add(p);
         _uow.SaveChanges();
         var added = _uow.Performances.Find(p.PerformanceId);
         return(_performanceFactory.Transform(added));
     }
     catch (DBConcurrencyException)
     {
         return(null);
     }
 }
 public void HandleCreate(CreateProductCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         if (company == null)
         {
             throw new DomainException("The assigned company not found");
         }
         User creator = uow.Users.FirstOrDefault(u => u.Id == command.CreatedByUserId);
         if (creator == null)
         {
             throw new DomainException("Can not find creator");
         }
         var product = new Product
         {
             Company    = company,
             Name       = command.Name,
             Comment    = command.Comment,
             Quantity   = command.Quantity,
             Sku        = command.Sku,
             Properties = new List <ProductProperty>(command.Properties),
             IsActive   = command.IsActive,
             CreatedAt  = DateTime.Now,
             CreatedBy  = creator
         };
         uow.ProductRepository.Add(product);
         uow.SaveChanges();
         command.ProductId = product.Id;
     }
 }
        public InvoiceDTO AddNewInvoice(InvoiceDTO newInvoice)
        {
            var l = _invoiceFactory.Transform(newInvoice);

            _uow.Invoices.Add(l);
            _uow.SaveChanges();
            return(_invoiceFactory.Transform(_uow.Invoices.Find(l.InvoiceId)));
        }
 /// <summary>
 /// Handle delete command.
 /// </summary>
 public void HandleDelete(DeleteCompanyCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         uow.CompanyRepository.Remove(company);
         uow.SaveChanges();
     }
 }
Esempio n. 16
0
        public AnswerDTO AddNewAnswer(AnswerDTO adto)
        {
            var newAnswer = _answerFactory.Create(adto);

            _uow.Answers.Add(newAnswer);
            _uow.SaveChanges();

            return(_answerFactory.Create(newAnswer));
        }
Esempio n. 17
0
        public TicketDTO AddNewTicket(TicketDTO dto)
        {
            if (dto == null)
            {
                return(null);
            }
            var ticket = _ticketFactory.Transform(dto);

            _uow.Tickets.Add(ticket);
            _uow.SaveChanges();
            return(_ticketFactory.Transform(_uow.Tickets.Find(ticket.TicketId)));
        }
 /// <summary>
 /// Handle update command.
 /// </summary>
 public void HandleUpdate(UpdateCompanyCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         if (uow.Companies.Any(c => c.Name == command.Name.Trim() && c.Id != command.CompanyId))
         {
             throw new DomainException("The company with the same name already exists.");
         }
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         company.Name = command.Name;
         uow.SaveChanges();
     }
 }
 public void HandleDelete(DeleteProductCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Product product = uow.ProductRepository.Get(command.ProductId, Product.IncludeAll);
         if (product == null)
         {
             throw new NotFoundException("Deleted product not found");
         }
         // Delete properties before
         uow.ProductPropertyRepository.RemoveRange(product.Properties);
         uow.ProductRepository.Remove(product);
         uow.SaveChanges();
     }
 }
 public void HandleUpdate(UpdateProductCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Product product = uow.ProductRepository.Get(command.ProductId, Product.IncludeAll);
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         if (company == null)
         {
             throw new DomainException("The assigned company not found");
         }
         User updater = uow.Users.FirstOrDefault(u => u.Id == command.UpdatedByUserId);
         if (updater == null)
         {
             throw new DomainException("Can not find updater");
         }
         // Delete properties
         foreach (ProductProperty removedProperty in product.Properties.Where(oldP => !command.Properties.Any(newP => newP.Id == oldP.Id)).ToList())
         {
             product.Properties.Remove(removedProperty);
             uow.ProductPropertyRepository.Remove(removedProperty);
         }
         // Update existing properties
         foreach (ProductProperty existProperty in product.Properties)
         {
             ProductProperty updatedProperty = command.Properties.SingleOrDefault(pp => pp.Id == existProperty.Id);
             existProperty.Name  = updatedProperty.Name;
             existProperty.Value = updatedProperty.Value;
         }
         // Add new properties
         foreach (ProductProperty property in command.Properties.Where(pp => pp.Id == 0))
         {
             product.Properties.Add(property);
         }
         product.Company   = company;
         product.Name      = command.Name;
         product.Comment   = command.Comment;
         product.Quantity  = command.Quantity;
         product.Sku       = command.Sku;
         product.IsActive  = command.IsActive;
         product.UpdatedAt = DateTime.Now;
         uow.SaveChanges();
     }
 }
 /// <summary>
 /// Handle create command.
 /// </summary>
 public void HandleCreate(CreateCompanyCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         if (uow.Companies.Any(c => c.Name == command.Name.Trim()))
         {
             throw new DomainException("The company with the same name already exists.");
         }
         User creator = uow.Users.FirstOrDefault(u => u.Id == command.CreatedByUserId);
         if (creator == null)
         {
             throw new DomainException("Cannot find creator.");
         }
         var company = new Company
         {
             Name      = command.Name,
             CreatedBy = creator
         };
         uow.CompanyRepository.Add(company);
         uow.SaveChanges();
         command.CompanyId = company.Id;
     }
 }