示例#1
0
        public IActionResult Add(string name, string url, string token)
        {
            Server s = new Server(name, url, token);

            _srvContext.Servers.Add(s);
            _srvContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
        public ActionResult Edit(Servers serverModel)
        {
            if (ModelState.IsValid)
            {
                using (var dbo = new ServersContext())
                {
                    var server = new Servers()
                    {
                        EnumStatus = serverModel.EnumStatus,
                        EnumType   = serverModel.EnumType,
                        Name       = serverModel.Name,
                        Password   = serverModel.Password,
                        Ip1        = serverModel.Ip1,
                        Ip2        = serverModel.Ip2,
                        Ip3        = serverModel.Ip3,
                        Details    = serverModel.Details
                    };
                    dbo.ServerList.Add(server);
                    dbo.SaveChanges();

                    return(Json(server, JsonRequestBehavior.AllowGet));
                }
            }
            throw new HttpException(400, "eroare in model");
        }
示例#3
0
 // GET: Servers/Delete/5
 public ActionResult Delete(int id)
 {
     using (var dbo = new ServersContext())
     {
         var item = dbo.ServerList.FirstOrDefault(x => x.ServerId == id);
         if (item != null)
         {
             dbo.ServerList.Remove(item);
             dbo.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
示例#4
0
        public ActionResult Create([Bind(Include = "ServerId,EnumStatus,EnumType,Name,Password,Ip1,Ip2,Ip3,Details")] Servers servers)
        {
            //dynamic validation from Controller
            if (string.IsNullOrEmpty(servers.Name))
            {
                ModelState.AddModelError("Name", "Ai uitat Numele!");
            }

            if (ModelState.IsValid)
            {
                db.ServerList.Add(servers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(servers));
        }