private void AddNewTitle() { Console.Write("Enter author's name: "); var firstName = Console.ReadLine(); Console.Write("Enter author's last name: "); var lastName = Console.ReadLine(); Author newAuthor = new Author(); newAuthor.FirstName = firstName; newAuthor.LastName = lastName; _authorRepository.AddAuthor(newAuthor); Console.Write("Enter book's title: "); var title = Console.ReadLine(); Console.Write("Enter book's genre: "); var genre = Console.ReadLine(); var authorId = _authorRepository.GetAllAuthors().Count(); Book newBook = new Book(); newBook.Title = title; newBook.Genre = genre; newBook.AuthorID = authorId; _bookRepository.AddBook(newBook); Console.WriteLine("The new title has been added successfully"); }
public bool AddAuthor(AuthorDTO author) { try { _repository.AddAuthor(author); } catch { return(false); } return(true); }
public IActionResult CreateAuthor(AuthorForCreationDto authorForCreationDto) { var authorDto = new AuthorDto { Name = authorForCreationDto.Name, Age = authorForCreationDto.Age, Email = authorForCreationDto.Email, }; AuthorRepository.AddAuthor(authorDto); return(CreatedAtRoute(nameof(GetAuthor), new { authorId = authorDto.Id }, authorDto)); }
private void AddNewAuthor() { System.Console.WriteLine("Enter author first name:"); string firstName = System.Console.ReadLine(); System.Console.WriteLine("Enter author last name:"); string lasttName = System.Console.ReadLine(); Author author = new Author(); author.FirstName = firstName; author.LastName = lasttName; _authors.AddAuthor(author); }
public async Task <bool> AddAuthor(Author author) { try { var status = await _authorRepository.AddAuthor(author); return(status); } catch (Exception ex) { new Logger().LogError(ModuleName, "AddAuthor", "Error Adding Author" + ex + "\n"); throw; } }
public ActionResult Create(Author newAuthor, IFormCollection collection) { if (!ModelState.IsValid) { return(View(newAuthor)); } try { _authorRepo.AddAuthor(newAuthor); return(RedirectToAction(nameof(Index))); } catch { return(View(newAuthor)); } }
public AddAuthorResult AddAuthor( [Inject] IAuthorRepository authorRepository, AddAuthorParams input) { var dto = new AuthorDto { FirstName = input.Author.Value.FirstName, LastName = input.Author.Value.LastName, }; dto.Id = authorRepository.AddAuthor(dto); return(new AddAuthorResult { Author = new Author(dto), }); }
public async Task <AddAuthorCommandResponseViewModel> Handle(AddAuthorCommand request, CancellationToken cancellationToken) { AddAuthorCommandResponseViewModel response = new AddAuthorCommandResponseViewModel(); Author author = new Author(Guid.NewGuid(), request.Name); if (!author.Validate()) { return(response); } await _authorRepository.AddAuthor(author); response.AuthorId = author.AuthorId; response.Name = author.Name; return(response); }
public async Task <IActionResult> CreateAuthor( [FromBody] AuthorForCreationDto authorForCreationDto) { if (authorForCreationDto == null) { return(BadRequest()); } var author = _mapper.Map <Entities.Author>(authorForCreationDto); _authorRepository.AddAuthor(author); await _authorRepository.SaveChangesAsync(); var authorToReturn = _mapper.Map <Models.AuthorDto>(author); return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn)); }
public async Task <IActionResult> Create(Author entity, IFormFile file) { if (ModelState.IsValid) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img", file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } entity.Image = file.FileName; entity.PostedDate = DateTime.Now; _authorRepo.AddAuthor(entity); return(RedirectToAction("Index")); } return(View(entity)); }
public async Task <bool> ExecuteAsync(ICreateAuthor input) { if (!validator.ValidateInput(input)) { return(false); } var author = Author.CreateNew(input.Name); if (author is Author.InvalidAuthor) { return(false); } await repository.AddAuthor(author); eventTriggers.OnAuthorAdded(this); return(true); }
public ActionResult AddAuthor([DataSourceRequest] DataSourceRequest request, AuthorViewModel model) { if (ModelState.IsValid) { try { AuthorsRepository.AddAuthor(new Author { FirstName = model.FirstName, LastName = model.LastName, BirthDate = model.BirthDate }); TempData["SuccessMessage"] = string.Format(model.FullName + " ავტორის დამატება განხორციელდა წარმატებულად"); } catch (Exception exc) { TempData["ErrorMessage"] = exc.Message; } } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
public IActionResult CreateAuthor([FromBody] AuthorCreateDTO authorCreateModel) { if (authorCreateModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var authorEntity = _mapper.Map <Author>(authorCreateModel); _authorRepository.AddAuthor(authorEntity); if (!_authorRepository.Save()) { throw new Exception("Kayit sirasinda hata olustu"); } return(CreatedAtRoute("GetAuthor", new { authorId = authorEntity.Id }, authorEntity)); }
public override async Task <UpdateAuthorRequest> HandleAsync(UpdateAuthorRequest command, CancellationToken cancellationToken = new CancellationToken()) { var result = await _authorRepository.GetAuthorById(command.LibraryId, command.Author.Id, cancellationToken); if (result == null) { var author = command.Author; author.Id = default(int); command.Result.Author = await _authorRepository.AddAuthor(command.LibraryId, author, cancellationToken); command.Result.HasAddedNew = true; } else { result.Name = command.Author.Name; result.Description = command.Author.Description; result.AuthorType = command.Author.AuthorType; await _authorRepository.UpdateAuthor(command.LibraryId, result, cancellationToken); command.Result.Author = command.Author; } return(await base.HandleAsync(command, cancellationToken)); }
public Author CreateAuthor(string name, DateTime?birthDate = default(DateTime?), DateTime?deathDate = default(DateTime?)) { return(authorRepo.AddAuthor(name, birthDate, deathDate)); }
public Author AddAuthor(Author author) { return(_authorRepository.AddAuthor(author)); }
/// <summary> /// 用户,组织创建权限 /// </summary> /// <param name="userId"></param> /// <param name="orgId"></param> /// <returns></returns> public OperationResult CreateAdminAuthor(string userId, string orgId) { OperationResult result = new OperationResult(); //用户对于的角色 UserRoleRelationDAO userRoleRelation = new UserRoleRelationDAO() { MItemID = GuidUtility.GetGuid(), MUserID = userId, MOrgID = orgId, //管理员 MRoleID = "10000" }; //获取用户组模型 UserGroupRelationDAO userGroupRelation = new UserGroupRelationDAO() { MItemID = GuidUtility.GetGuid(), MUserID = userId, MOrgID = orgId, MGroupID = "10000" }; GroupRoleRealtionDAO groupRoleRealtion = new GroupRoleRealtionDAO() { MGroupID = "10000", MRoleID = "10000", MItemID = GuidUtility.GetGuid(), }; //获取角色,权限关系模型 List <RolePermisionRelationDAO> rolePermisionRelations = GetRolePermisionRelations(orgId, "10000", "11111"); //获取角色,权限关系模型 List <GroupPermissionRelationDAO> groupPermisionRelations = GetGroupPermisionRelations(orgId, "10000", "11111"); try { result.Success = _authorRepository.AddAuthor(userGroupRelation, userRoleRelation, rolePermisionRelations, groupPermisionRelations); //如果成功,返回一个权限创建成功队列 if (result.Success) { AuthorCreatedEvent @event = new AuthorCreatedEvent() { OrgId = orgId, UserId = userId }; _eventBus.PublishAsync <AuthorCreatedEvent>(@event); } else { OrganizationRollbackEvent @event = new OrganizationRollbackEvent() { OrgId = orgId }; _eventBus.PublishAsync <OrganizationRollbackEvent>(@event); } } catch (Exception ex) { //如果创建失败,发送一个组织回滚事件 OrganizationRollbackEvent @event = new OrganizationRollbackEvent() { OrgId = orgId }; _eventBus.PublishAsync <OrganizationRollbackEvent>(@event); } return(result); }
public void AddAuthor(Author author) { authorRepo.AddAuthor(author); }
public override async Task <AddAuthorRequest> HandleAsync(AddAuthorRequest command, CancellationToken cancellationToken = new CancellationToken()) { command.Result = await _authorRepository.AddAuthor(command.LibraryId, command.Author, cancellationToken); return(await base.HandleAsync(command, cancellationToken)); }
public Author AddAuthor(Author newAuthor) { return(_repo.AddAuthor(newAuthor)); }
public void Add(Author author) { _authorRepository.AddAuthor(author); }
public async Task AddAuthor(AuthorDto newAuthor) { var author = _mapper.Map <AuthorDto, Author>(newAuthor); await _repository.AddAuthor(author); }
public async Task <IActionResult> AddAuthor(Author author) { await _repository.AddAuthor(author); return(Created($"/api/Author/author.id", new { author.Id })); }
public string Get(string setting) { if (setting == "init") { _authorRepository.RemoveAllAuthors(); _authorRepository.AddAuthor(new Author() { AuthorId = 1, Name = "Jules Verne", Age = 48, CreatedDate = DateTime.Now }); _authorRepository.AddAuthor(new Author() { AuthorId = 2, Name = "Carl Sagan", Age = 52, CreatedDate = DateTime.Now }); _authorRepository.AddAuthor(new Author() { AuthorId = 3, Name = "Stephen Hawking", Age = 50, CreatedDate = DateTime.Now }); _bookRepository.RemoveAllBooks(); _bookRepository.AddBook(new Book() { ISBN = "123qwe123qwe", BookName = "The Mysterious Island", CreatedDate = DateTime.Now, Price = Convert.ToDecimal("3.50"), Author = _authorRepository.GetAuthorById(1) }); _bookRepository.AddBook(new Book() { ISBN = "456rty456rty", BookName = "Cosmos", CreatedDate = DateTime.Now, Price = Convert.ToDecimal("4.00"), Author = _authorRepository.GetAuthorById(2) }); _bookRepository.AddBook(new Book() { ISBN = "789uop789uop", BookName = "Black Holes", CreatedDate = DateTime.Now, Price = Convert.ToDecimal("5.00"), Author = _authorRepository.GetAuthorById(3) }); return("Database BookStoreDb was created, and collection 'Books and Authors' were filled with 3 sample items"); } return("Unknown"); }
public async Task <ActionResult <Author> > Post([FromBody] Author author) { var newAuthor = await _authorRepository.AddAuthor(author); return(CreatedAtAction(nameof(Get), new { id = newAuthor.Id }, newAuthor)); }
public async Task <Author> AddAuthor(Author author) { return(await _authorrepository.AddAuthor(author)); }