public async Task Create(CreateServiceDTO dto) { try { var CreatedService = new ServiceDbEntity(); CreatedService.Title = dto.Title; CreatedService.Description = dto.Description; CreatedService.SubSectionId = dto.SubSectionId; CreatedService.ServiceProviderId = dto.ServiceProviderId; _DB.Services.Add(CreatedService); _DB.SaveChanges(); foreach (var file in dto.Files) { var fileName = await _fileService.SaveFile(file, "Files"); var fileEntity = new FileDbEntity(); fileEntity.ServiceId = CreatedService.Id; fileEntity.FilePath = fileName; _DB.Files.Add(fileEntity); } _DB.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public async Task <ActionResult <ServiceDTO> > Post(CreateServiceDTO dto) { if (dto == null) { throw new ArgumentNullException(); } var existingService = _service.Get(dto.Code); if (existingService != null) { throw new HttpResponseException($"Service with code '{dto.Code}' already exists"); } var model = _mapper.Map <ServiceModel>(dto); if (model == null) { throw new HttpResponseException("Unable to map dto"); } model = await Task.Run(() => _service.Create(model)); var result = _mapper.Map <ServiceDTO>(model); await DropServiceCacheAsync(string.Empty); return(Ok(result)); }
//[AbpAuthorize(PermissionNames.Pages_Service_Create)] public async Task <ServiceDTO> CreateServiceAsync(CreateServiceDTO input) { var service = ObjectMapper.Map <Service>(input); service = await _serviceRepo.InsertAsync(service); await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <ServiceDTO>(service)); }
public async Task <bool> CreateAsync([FromBody] CreateServiceDTO dto) { if ((await _dbContext.Services.FirstOrDefaultAsync(x => x.Name == dto.Name.Trim())) != null) { throw new ApplicationException("Service exists"); } var entity = new Service(dto.Name, dto.SecurityToken, dto.Description); entity.SetCreationAudited(Session.UserId, Session.UserName); entity.SetModificationAudited(Session.UserId, Session.UserName, DateTimeOffset.Now); await _dbContext.Services.AddAsync(entity); await _dbContext.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Create([FromForm] CreateServiceDTO dto) { await _ServiceService.Create(dto); return(Ok(GetResponse("Added"))); }
public async Task <IActionResult> Create(CreateServiceDTO input) { var newService = await _serviceAppService.CreateServiceAsync(input); return(Ok(newService)); }