public ActionResult EditPublisher(PublisherVM myModel, FormCollection collection) { if (!User.IsInRole("Admin")) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 403." , errorDetail = "Bạn không có quyền truy cập" })); } if (ModelState.IsValid) { db.Entry(myModel.Publisher).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("EditPublisher", "Staff", new { publisherId = myModel.Publisher.ID, success = true, })); } ViewBag.IsAdmin = true; ViewBag.User = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); return(View()); }
public void InsertPublisher(PublisherVM pub) { pub.CreatedBy = 1; pub.CreatedDate = DateTime.Now; if (pub.PublisherUrl == null) { var url = ExcellentMarketResearch.Areas.Admin.Models.Common.GenerateSlug(pub.PublisherName); pub.PublisherUrl = url; } JavaScriptSerializer serializer = new JavaScriptSerializer(); var c = serializer.Serialize(pub); PublisherMaster pubmaster = serializer.Deserialize <PublisherMaster>(c); try { db.PublisherMasters.Add(pubmaster); db.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } }
public async Task <IActionResult> AddPublisher([FromBody] PublisherVM publisher) { IEnumerable <Publisher> pubs = await _publisherService.GetAll(); bool exist = false; //PublisherVM pub = JsonConvert.DeserializeObject<PublisherVM>(publisher); PublisherVM pub = publisher; if (pubs.Any()) { foreach (Publisher p in pubs) { if (p.Name.ToLower() == pub.Name.ToLower() && p.Location.ToLower() == pub.Location.ToLower()) { exist = true; } } } if (!exist) { await _publisherService.Add(new Publisher(pub.Name, pub.Location)); } pubs = await _publisherService.GetAll(); List <PublisherViewModel> pubList = new List <PublisherViewModel>(); foreach (Publisher p in pubs) { pubList.Add(new PublisherViewModel(p.Id, p.Name, p.Location)); } return(Json(pubList)); }
public ActionResult EditPublisher(int?publisherId, bool success = false) { if (!User.IsInRole("Admin")) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 403." , errorDetail = "Bạn không có quyền truy cập" })); } if (publisherId == null) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 404." , errorDetail = "Không xác định nhà sản xuất / nhà xuất bản" })); } ViewBag.IsAdmin = true; ViewBag.User = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); return(View(PublisherVM.GeneratePublisherVM(db, publisherId, success))); }
public ActionResult DeleteConfirmed(int id, PublisherVM publisherVM) { var query = db.Publishers.Single(p => p.PublisherID == id); var publisher = Mapper.Map <Publisher, PublisherVM>(query); db.Publishers.Remove(query); // db.SaveChanges(); return(RedirectToAction("Index")); }
public PublisherWindow() { InitializeComponent(); _vm = new PublisherVM(); DataContext = _vm; _vm.ProgressChanged += OnProgressChanged; _vm.Finished += OnFinished; }
public void AddPublisher_WithException_Test() { var newPublisher = new PublisherVM() { Name = "123 With Exception" }; Assert.That(() => publishersService.AddPublisher(newPublisher), Throws.Exception.TypeOf <PublisherNameException>().With.Message.EqualTo("Name starts with number")); }
public void AddPublisher(PublisherVM publisherVm) { var publisher = new Publisher { Name = publisherVm.Name }; _context.Publishers.Add(publisher); _context.SaveChanges(); }
public void AddPublisher(PublisherVM publisher) { var _publisher = new Publisher() { Name = publisher.Name }; _context.Publishers.Add(_publisher); _context.SaveChanges(); }
public void AddPublisher(PublisherVM publisher) { var _publisher = new Publisher() { Publisher_Name = publisher.Publisher_Name }; dbContext.Publishers.Add(_publisher); dbContext.SaveChanges(); }
public void PublisherEdit(PublisherVM pub) { pub.ModifiedBy = 1; pub.ModifiedDate = DateTime.Now; JavaScriptSerializer serializer = new JavaScriptSerializer(); var publish = serializer.Serialize(pub); PublisherMaster pubmast = serializer.Deserialize <PublisherMaster>(publish); db.Entry(pubmast).State = EntityState.Modified; db.SaveChanges(); }
public ActionResult Edit(PublisherVM publisherVM) { if (ModelState.IsValid) { var publisher = Mapper.Map <Publisher>(publisherVM); db.Entry(publisher).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(publisherVM)); }
public void HTTPPOST_AddPublisher_ReturnsCreated_Test() { var newPublisherVM = new PublisherVM() { Name = "New Publisher" }; IActionResult actionResult = publishersController.AddPublisher(newPublisherVM); Assert.That(actionResult, Is.TypeOf <CreatedResult>()); }
public IActionResult AddPublisher([FromBody] PublisherVM publisher) { try { var _result = _publishersService.AddPublisher(publisher); return(Created(nameof(AddPublisher), _result)); } catch (PublisherNameException ex) { return(BadRequest($"{ex.Message}, Publisher Name: {ex.PublisherName}")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void HTTPPOST_AddPublisher_ReturnsBadRequest_Test() { var newPublisherVM = new PublisherVM() { Name = "123 New Publisher" }; IActionResult actionResult = publishersController.AddPublisher(newPublisherVM); Assert.That(actionResult, Is.TypeOf <BadRequestObjectResult>()); }
public ActionResult Create(PublisherVM publisherVM) { if (ModelState.IsValid) { var publisher = Mapper.Map <Publisher>(publisherVM); db.Publishers.Add(publisher); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(publisherVM)); }
public IActionResult AddPublisher([FromBody] PublisherVM publisher) { try { var newPublisher = _publishersService.AddPublisher(publisher); return(Created(nameof(AddPublisher), newPublisher)); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }
public void AddPublisher_WithoutException_Test() { var model = new PublisherVM() { Name = "Without Exception" }; var result = publisherService.AddPublisher(model); Assert.That(result, Is.Not.Null); Assert.That(result.Name, Does.StartWith("Without")); Assert.That(result.Id, Is.Not.Null); }
public Publisher AddPublisher(PublisherVM publisher) { if (StringStartsWithNumber(publisher.Name)) { throw new PublisherNameException("Name starts with number", publisher.Name); } var _publisher = new Publisher() { Name = publisher.Name }; _context.Publishers.Add(_publisher); _context.SaveChanges(); return(_publisher); }
public ActionResult AddPublisher(bool success = false) { if (!User.IsInRole("Admin")) { return(RedirectToAction("Error" , new { errorCode = "Lỗi 403." , errorDetail = "Bạn không có quyền truy cập" })); } ViewBag.IsAdmin = true; ViewBag.User = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault(); return(View(PublisherVM.GeneratePublisherVM(db, success))); }
public IActionResult addPublishers([FromBody] PublisherVM publisher) { publisherServices.AddPublisher(publisher); return(Ok()); }
public PushZipStepVM(PublisherVM vm) : base(vm) { }
public IActionResult AddPublisher([FromBody] PublisherVM publisher) { _publishersService.AddPublisher(publisher); return(Ok()); }
public IActionResult AddPublisher(PublisherVM publisherVm) { _publisherServices.AddPublisher(publisherVm); return(Ok()); }
public ActionResult PublisherCreate(PublisherVM pub) { _ObjPublisherRepository.InsertPublisher(pub); return(RedirectToAction("PublisherIndex")); }
public ActionResult PublisherEdit(PublisherVM pub) { _ObjPublisherRepository.PublisherEdit(pub); return(RedirectToAction("PublisherIndex")); }
public IActionResult AddBook([FromBody] PublisherVM publisher) { var newPublisher = _publisherrService.AddPublisher(publisher); return(Created(nameof(AddBook), newPublisher)); }