static void Main(string[] args) { Blog xmfdsh = new MyBlog("xmfdsh", "发布了一篇新博客"); Subscriber wnm = new Subscriber("王尼玛"); Subscriber tmr = new Subscriber("唐马儒"); Subscriber wmt = new Subscriber("王蜜桃"); Subscriber anm = new Subscriber("敖尼玛"); // 添加订阅者 xmfdsh.AddObserver(new NotifyEventHandler(wnm.Receive)); xmfdsh.AddObserver(new NotifyEventHandler(tmr.Receive)); xmfdsh.AddObserver(new NotifyEventHandler(wmt.Receive)); xmfdsh.AddObserver(new NotifyEventHandler(anm.Receive)); xmfdsh.Update(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("移除订阅者王尼玛"); xmfdsh.RemoveObserver(new NotifyEventHandler(wnm.Receive)); xmfdsh.Update(); Console.ReadLine(); }
public ActionResult DeleteConfirmed(int id) { MyBlog myBlog = db.MyBlogs.Find(id); db.MyBlogs.Remove(myBlog); db.SaveChanges(); return(RedirectToAction("Index")); }
// Use this for initialization void Start() { mBlog b = new MyBlog("你看我像谁", "发布了一篇微博"); b.AddObserver(new Subscribe("金装")); b.AddObserver(new Subscribe("Sony")); b.Update(); //StartCoroutine("coRoutine"); }
public ActionResult Edit([Bind(Include = "Id,Image,Title,Content,History,Share,Network")] MyBlog myBlog) { if (ModelState.IsValid) { db.Entry(myBlog).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(myBlog)); }
public ActionResult Create([Bind(Include = "Id,Image,Title,Content,History,Share,Network")] MyBlog myBlog) { if (ModelState.IsValid) { db.MyBlogs.Add(myBlog); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(myBlog)); }
public ActionResult ViewMy(string para) { if (Check()) { return(RedirectToAction("Index", "Login")); } Int32 id = Int32.Parse(para); BlogClient service = new BlogClient(); MyBlog stu = service.GetBlogById(id); return(View(stu)); }
public static Blog From(MyBlog.Model.Blog blog) { return new Blog { Content = blog.Content, CreateDate = blog.CreateDate, Id = blog.Id, CreateId = blog.CreateId, LastUpdateDate = blog.LastUpdateDate, Status = blog.Status, Title = blog.Title, Type = blog.Type }; }
// GET: MyBlog/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MyBlog myBlog = db.MyBlogs.Find(id); if (myBlog == null) { return(HttpNotFound()); } return(View(myBlog)); }
static void Main(string[] args) { //观察者模式 Blog xmf = new MyBlog("苏翅", $"发表了一张照片,点击链接查看!"); SubScriber wnn = new SubScriber("王妮娜"); SubScriber tmr = new SubScriber("唐马儒"); SubScriber wmt = new SubScriber("王蜜桃"); SubScriber anm = new SubScriber("敖尼玛"); // 添加订阅者 xmf.AddObserver(new NotifyEventHandler(wnn.Receive)); xmf.AddObserver(new NotifyEventHandler(tmr.Receive)); xmf.AddObserver(new NotifyEventHandler(wmt.Receive)); xmf.AddObserver(new NotifyEventHandler(anm.Receive)); xmf.Update(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); xmf.RemoveObserver(new NotifyEventHandler(wnn.Receive)); Console.WriteLine($"移除订阅者{wnn.Name}"); xmf.Update(); Console.ReadKey(); return; IOprFactory oprsub = new SubFactory(); IOprFactory opradd = new AddFactory(); Opreator otsub = oprsub.CreateOperation(); otsub.A = 33; otsub.B = 22; Opreator otadd = opradd.CreateOperation(); otadd.A = 8; otadd.B = 16; Trace.WriteLine($"SUB:{otsub.A}-{otsub.B}={otsub.GetResult()}"); Trace.WriteLine($"ADD:{otadd.A}+{otadd.B}={otadd.GetResult()}"); //A a = new A("1"); //A aa = new A() { b = "1" }; //Console.WriteLine(aa.b + a.b); //Console.ReadKey(); //return; IDoctor d = new DoctorProvider(); Trace.WriteLine($"old driver name is { d.GetDoctorName()} and {d.GetDoctorAge()} age now!!"); }
public ActionResult Blog(string title, string content, string blogby) { if (Check()) { return(RedirectToAction("Index", "Login")); } BlogClient service = new BlogClient(); MyBlog stu = new MyBlog(); stu.blogby = blogby; stu.content = content; stu.title = title; stu.uid = (int)Session["uid"]; string p = service.AddBlog(stu); return(View()); }
public ActionResult UpdateBlog(string blog, string title, string content) { if (Check()) { return(RedirectToAction("Index", "Login")); } BlogClient service = new BlogClient(); MyBlog stu = new MyBlog(); stu.blogNO = Int32.Parse(blog); stu.title = title; stu.content = content; string mess = service.UpdateBlog(stu); return(RedirectToAction("Update", new { updateblogNO = blog })); }
public BlogCollection(IEnumerable<Blog> blogs, MyBlog.Model.PageInfo pageInfo) { this._blogs = blogs; this._pageInfo = pageInfo; }
static void Main(string[] args) { Blog xmfdsh = new MyBlog("xmfdsh", "发布了一篇新博客"); List <Subscriber> sub = new List <Subscriber>() { new Subscriber("王尼玛"), new Subscriber("唐马儒"), new Subscriber("王蜜桃"), new Subscriber("敖尼玛") }; // 添加订阅者 foreach (var item in sub) { xmfdsh.AddObserver(new NotifyEventHandler(item.Receive)); } xmfdsh.Update(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("移除订阅者王尼玛"); foreach (var item in sub) { if (item.Name.Equals("王尼玛")) { xmfdsh.RemoveObserver(new NotifyEventHandler(sub[sub.IndexOf(item)].Receive)); break; } } xmfdsh.Update(); while (true) { Console.WriteLine("请选择操作,1:添加订阅者,2:移除订阅者,N:终止操作"); var op = Console.ReadLine(); var ops = new List <string>() { "1", "2", "N" }; if (!ops.Contains(op)) { Console.WriteLine("输入命令操作不合法,请重新输入!"); } if (op == "1") { Console.WriteLine("请输入您要添加的订阅者姓名"); var name = Console.ReadLine(); Subscriber reader = new Subscriber(name); sub.Add(reader); xmfdsh.AddObserver(new NotifyEventHandler(reader.Receive)); Console.WriteLine("{0}订阅者添加成功!", name); } if (op == "2") { Console.WriteLine("请输入您要移除的订阅者姓名"); var name = Console.ReadLine(); Subscriber reader = new Subscriber(name); foreach (var item in sub) { if (item.Name.Equals(name)) { xmfdsh.RemoveObserver(new NotifyEventHandler(sub[sub.IndexOf(item)].Receive)); break; } } Console.WriteLine("{0}订阅者移除成功!", name); } if (op == "N") { xmfdsh.Update(); break; } } }