示例#1
0
        public ActionResult Edit(Publisher publisher)
        {
            if (ModelState.IsValid)
            {
                Publisher newPublisher = publisherManager.Find(x => x.Id == publisher.Id);

                newPublisher.Name     = publisher.Name;
                newPublisher.Id       = publisher.Id;
                newPublisher.IsActive = true;
                if (publisherManager.Update(newPublisher) > 0)
                {
                    OkViewModel ok = new OkViewModel()
                    {
                        Title          = "Yayınevi güncelleme işleminiz başarılı",
                        RedirectingUrl = "/Publisher/Index"
                    };

                    return(View("Ok", ok));
                }
                ErrorViewModel error = new ErrorViewModel()
                {
                    Title          = "Yazar güncelleme işleminiz başarısız",
                    RedirectingUrl = "/Publisher/Index"
                };
                return(View("Error", error));
            }
            return(View(publisher));
        }
示例#2
0
        static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            var connectionstring = config["ConnectionString"];

            //Console.WriteLine(connectionstring);

            //Console.ReadKey();

            IPublisherManager publisherManager = new PublisherManager(connectionstring);

            //int result = publisherManager.Create(new Entities.Publisher
            //{
            //    PublisherId = 1,
            //    Name = "Andrei"
            //});

            //Publisher publisher = publisherManager.Read(1);

            int result2 = publisherManager.Update(new Publisher
            {
                PublisherId = 1,
                Name        = "Vlad"
            });
        }
示例#3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool add = txtId.Text == "" ? false : true;

            if (!add)
            {
                PublisherBindingModel model = new PublisherBindingModel()
                {
                    Name = txtName.Text
                };

                if (manager.Create(model))
                {
                    add = false;
                    MessageBox.Show("Thêm mới thành công !", "Thông báo");
                }
                else
                {
                    MessageBox.Show("Thêm mới không thành công!. Liên hệ với quản trị viên.", "Thông báo");
                }
            }
            else
            {
                PublisherBindingModel model = new PublisherBindingModel()
                {
                    Id   = int.Parse(txtId.Text),
                    Name = txtName.Text
                };

                if (manager.Update(model))
                {
                    MessageBox.Show("Sửa thành công !", "Thông báo");
                }
                else
                {
                    MessageBox.Show("Sửa không thành công!. Liên hệ với quản trị viên.", "Thông báo");
                }
            }

            LoadData(Searching, PageIndex, PageSize);
        }
        public ActionResult Edit(int id, string name)
        {
            if (name.Trim() == "")
            {
                TempData["message"] = "出版社名称不能为空";
                return(RedirectToAction("Edit", "Publisher", new { Id = id }));
            }
            if (pm.Exists(name.Trim(), id))
            {
                TempData["message"] = "已经存在这个出版社名称";
                return(RedirectToAction("Edit", "Publisher", new { Id = id }));
            }
            Publisher p = new Publisher {
                Id   = id,
                Name = name.Trim()
            };

            pm.Update(p);
            TempData["message"] = "修改出版社成功";
            return(RedirectToAction("Index", "Publisher"));
        }
 public HttpResponseMessage Patch(string id, [FromBody] PublisherModel model)
 {
     try
     {
         PublisherDTO dto = modelfactory.Parse(model);
         if (publishermanager.Update(id, dto))
         {
             return(Request.CreateResponse(HttpStatusCode.OK, "Publisher Updated Successfully"));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "Updating Publisher Failed"));
         }
     }
     catch (InvalidPublisherException ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }