예제 #1
0
 public static LocationDomain Create(AddLocationModel addLocationModel)
 {
     return(new LocationDomain(
                addLocationModel.Title,
                addLocationModel.FacultyId
                ));
 }
예제 #2
0
        public void AddLocation(AddLocationModel addLocationModel)
        {
            var model = new Location
            {
                Name       = addLocationModel.Name,
                CreateDate = DateTime.Now.ToUniversalTime()
            };

            try
            {
                _locationRepository.Add(model);
                _locationRepository.Save();
                _logger.LogInformation($"Location with id {model.Id} has been created");
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error when creating location");
                throw;
            }
        }
        public async Task <IDataResult <long> > AddAsync(AddLocationModel addLocationModel)
        {
            var validation = new LocationModelValidator().Valid(addLocationModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <long>(validation.Message));
            }

            var locationDomain = LocationDomainFactory.Create(addLocationModel);

            locationDomain.Add();

            var locationEntity = locationDomain.Map <LocationEntity>();

            await LocationRepository.AddAsync(locationEntity);

            await DatabaseUnitOfWork.SaveChangesAsync();

            return(new SuccessDataResult <long>(locationEntity.LocationId));
        }
        public async Task <IActionResult> AddAsync(AddLocationModel addLocationModel)
        {
            var result = await LocationService.AddAsync(addLocationModel);

            return(new ActionIResult(result));
        }