public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] PublishingCompany publishingCompany) { if (id != publishingCompany.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(publishingCompany); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublishingCompanyExists(publishingCompany.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(publishingCompany)); }
public async Task <PublishingCompany> AddAsync(PublishingCompany publishingCompany) { context.PublishingCompanies.Add(publishingCompany); await context.SaveChangesAsync(); return(publishingCompany); }
public void TestUpdatePublishingCompanyWithNullData() { PublishingCompany nullPublishingCompany = null; Assert.Throws <ArgumentNullException>(() => this.PublishingCompanyService.Update(nullPublishingCompany)); this.LibraryContextMock.Verify(b => b.SaveChanges(), Times.Never()); }
public async Task <Response> Store(PublishingCompany publishingCompany) { Response response = new Response { PublishingCompany = publishingCompany }; try { if (!PublishingCompanyExist(publishingCompany.Name)) { Context.Add(publishingCompany); await Context.SaveChangesAsync(); response.Message = "Editora cadastrada com sucesso!"; } else { response.Message = "Editora já cadastrada!"; response.BadRequest = true; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } return(response); }
public void TestDeletePublishingCompanyWithInvalidData() { var publishingCompany = new PublishingCompany(); var results = this.PublishingCompanyService.Delete(publishingCompany); Assert.IsNotEmpty(results); this.LibraryContextMock.Verify(b => b.SaveChanges(), Times.Never()); }
void DropDownAddClickedDym(object sender, DropDownAdd.SelectedItemEventArgs e) { //List<string> s = db.PublishingCompanies.Select(s => s.ToString()).ToList(); List <string> s = new PublishingCompany().getParam(); var value = e.SelectedChoice; DymAdd add_Window = new DymAdd(); add_Window.elements = s; add_Window.Title = "adfad"; add_Window.Show(); }
public ActionResult Edit(PublishingCompany collection) { if (ModelState.IsValid) { SetAlert("Update success", "success"); new PublishingCompanyModel().UpdateAtID(collection); return(RedirectToAction("Index")); } SetAlert("Update failed", "danger"); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,Name")] PublishingCompany publishingCompany) { if (ModelState.IsValid) { _context.Add(publishingCompany); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(publishingCompany)); }
public PublishingCompany Update(PublishingCompany entity) { var obj = ById(entity.Id); if (obj != null) { _data.Remove(obj); _data.Add(entity); } return(ById(entity.Id)); }
public void TestAddInvalidNameLowerBoundary() { var publishingCompany = new PublishingCompany { Name = string.Empty }; var results = this.PublishingCompanyService.Create(publishingCompany); var tag = results.FirstOrDefault(res => res.Tag == "PublishingCompanyNameLength"); Assert.IsNotNull(tag); this.LibraryContextMock.Verify(b => b.SaveChanges(), Times.Never()); }
public void TestAddNullName() { var publishingCompany = new PublishingCompany { Name = null }; var results = this.PublishingCompanyService.Create(publishingCompany); var tag = results.FirstOrDefault(res => res.Tag == "PublishingCompanyNameNull"); Assert.IsNotNull(tag); this.LibraryContextMock.Verify(b => b.SaveChanges(), Times.Never()); }
public void TestAddEmptyPublications() { var publishingCompany = new PublishingCompany { Publications = new List <Publication>() }; var results = this.PublishingCompanyService.Create(publishingCompany); var tag = results.FirstOrDefault(res => res.Tag == "PublishingCompanyPublicationsNull"); Assert.IsNull(tag); this.LibraryContextMock.Verify(b => b.SaveChanges(), Times.Never()); }
public bool CreatePublishingCompany(PublishingCompanyCreate model) { var entity = new PublishingCompany() { PublishingCompanyName = model.PublishingCompanyName, PublishingCompanyAddress = model.PublishingCompanyAddress }; using (var ctx = new ApplicationDbContext()) { ctx.PublishingCompanies.Add(entity); return(ctx.SaveChanges() == 1); } }
/// <summary> /// Post the new Publisher to the Repository. /// </summary> /// <param name="publishingCompany"></param> public static void PostPublishingCompanyToRepository(PublishingCompany publishingCompany) { if (!string.IsNullOrEmpty(publishingCompany.Name)) { } ; if (VerifyPublishingCompany(publishingCompany.Name) == -1) { publishingCompany.Id = PublishingCompany.Count; PublishingCompany.Count++; publishingCompany.NumberOfBooks++; Publishers.Add(publishingCompany); } }
public int Create(PublishingCompany e) { object[] paremeter = { new SqlParameter("Name", e.Name == null?(object)DBNull.Value:e.Name), new SqlParameter("MetaTitle", e.MetaTitle == null?(object)DBNull.Value:e.MetaTitle), new SqlParameter("PhoneNumber", e.PhoneNumber == null?(object)DBNull.Value:e.PhoneNumber), new SqlParameter("DisplayOrder", e.DisplayOrder == null?(object)DBNull.Value:e.DisplayOrder), new SqlParameter("CreateBy", e.CreateBy == null?(object)DBNull.Value:e.CreateBy), new SqlParameter("Status", e.Status) }; var res = context.Database.ExecuteSqlCommand("SP_PublishingCompany_Create @Name,@MetaTitle,@PhoneNumber,@DisplayOrder,@CreateBy,@Status", paremeter); return(res); }
public void TestPublishingCompanyGetterSetterId() { int id = 5; var publishingCompany = new PublishingCompany { Name = "RAO", Publications = new List <Publication> { new Publication { CoverType = Cover.HardCover } } }; typeof(PublishingCompany).GetProperty(nameof(PublishingCompany.Id)).SetValue(publishingCompany, id); Assert.IsTrue(id == publishingCompany.Id); }
protected void addBook_Click(object sender, EventArgs e) { try { Book book = new Book(bookName.Text, int.Parse(bookQPages.Text), double.Parse(bookValue.Text)); Author author = new Author(authorName.Text, 17); BllAuthor.insertAuthor(author); PublishingCompany company = new PublishingCompany(publishCompanyName.Text, "Rua x", "AZ"); bllCompany.inserPublishCompany(company); bllBooks.insertBook(book, author.Id, company.Id); fiilTable(); } catch (Exception error) { messager.Text = error.Message; } }
public void TestAddPublishingCompanyWithValidData() { var publishingCompany = new PublishingCompany { Name = "Litera", Publications = new List <Publication> { new Publication { CoverType = Cover.PaperBack } } }; var results = this.PublishingCompanyService.Create(publishingCompany); Assert.IsEmpty(results); this.LibraryContextMock.Verify(b => b.SaveChanges(), Times.Once()); }
public Response Validate(PublishingCompany publishingCompany) { IsValid = true; Response response = new Response(); try { if (publishingCompany.Name == null) { response.BadRequest = true; response.Message = "Insira o nome da editora!"; IsValid = false; } if (publishingCompany.Foundation == null) { response.BadRequest = true; response.Message = "Insira a data de fundação da editora!"; IsValid = false; } if (publishingCompany.Website == null) { response.BadRequest = true; response.Message = "Insira o site da editora!"; IsValid = false; } if (publishingCompany.Headquarters == null) { response.BadRequest = true; response.Message = "Insira a sede da editora!"; IsValid = false; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; IsValid = false; } return(response); }
public async Task UpdateAsync(PublishingCompany publishingCompany) { bool hasAny = await _context.PublishingCompanies.AnyAsync(x => x.Id == publishingCompany.Id); if (!hasAny) { throw new DllNotFoundException("Id not found"); } try { _context.Update(publishingCompany); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { throw new DbUpdateConcurrencyException(e.Message); } }
public void SetViewBag(int?selectPublishingCommpany = -1, int?selectAuthor = -1, int?selectRootCategory = null, string IDCategorys = null) { var list = new CategoryModel().GetAll(); ViewBag.IDRootCategory = new SelectList(list.Where(x => x.IDParent == null), "ID", "Name", selectRootCategory); var listPublishingCommpany = new PublishingCompanyModel().GetPublishingCompanys(); var defual = new PublishingCompany(); defual.ID = null; defual.Name = "n/a"; listPublishingCommpany.Insert(0, defual); ViewBag.IDPublishingCompany = new SelectList(listPublishingCommpany, "ID", "Name", selectPublishingCommpany); var listAuthor = new AuthorModel().GetAuthors(); var defual2 = new Author(); defual2.ID = null; defual2.Name = "n/a"; listAuthor.Insert(0, defual2); ViewBag.IDAuthor = new SelectList(listAuthor, "ID", "Name", selectAuthor); }
public PublishingCompany Add(PublishingCompany t) { return(_repository.Insert(t)); }
public async Task UpdateAsync(PublishingCompany publishingCompany) { context.PublishingCompanies.Update(publishingCompany); await context.SaveChangesAsync(); }
public async Task DeleteAsync(PublishingCompany publishingCompany) { context.PublishingCompanies.Remove(publishingCompany); await context.SaveChangesAsync(); }
public void Put(int id, [FromBody] PublishingCompany publishingCompany) { Repository.Publishers[id - 1].Name = publishingCompany.Name; }
public async Task <ActionResult <PublishingCompany> > Store([FromServices] OceanOfLettersContext _context, PublishingCompany publishingCompany) { Response response = new Response(); Validations.Validations validation = new Validations.Validations(); try { response = validation.Validate(publishingCompany); if (validation.IsValid) { response = await new PublishingCompaniesApplication(_context).Store(publishingCompany); } else { response.BadRequest = true; } } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } if (response.BadRequest) { return(BadRequest(response)); } else { return(CreatedAtAction("GetPublishingCompany", new { id = publishingCompany.Id }, response)); } //_context.PublishingCompany.Add(publishingCompany); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetPublishingCompany", new { id = publishingCompany.Id }, publishingCompany); }
public async Task <IActionResult> PutPublishingCompany([FromServices] OceanOfLettersContext _context, int id, PublishingCompany publishingCompany) { if (id != publishingCompany.Id) { return(BadRequest()); } _context.Entry(publishingCompany).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublishingCompanyExists(_context, id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void inserPublishCompany(PublishingCompany company) { string query = string.Format($@"insert into TBL_Editora (idEditora,nome,endereco,UF) values('{company.Id}','{company.Name}','{company.Address}','{company.Uf}')"); database.executeCommand(query); }
public async Task InsertAsync(PublishingCompany publishingCompany) { _context.Add(publishingCompany); await _context.SaveChangesAsync(); }
public PublishingCompany Change(PublishingCompany t) { return(_repository.Update(t)); }