Exemple #1
0
 public ActionResult AddClient(Client client)
 {
     if (ModelState.IsValid)
     {
         ClientRepo cl = new ClientRepo();
         if (cl.FindClient((long)client.Id) != null)
         {
             cl.ChangeClient(client);
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             if (cl.CheckUsername(client.UserName))
             {
                 ViewBag.Message = "Sorry, this nickname already in use";
                 return(PartialView());
             }
             else
             {
                 cl.AddClient(client);
                 client = cl.FindClient(client.UserName);
                 HttpCookie cookie = new HttpCookie("Auth");
                 cookie["AuthUser"] = client.UserName;
                 cookie["UserID"]   = client.Id.ToString();
                 cookie.Expires     = DateTime.Now.AddDays(1);
                 Response.Cookies.Add(cookie);
                 Session.Clear();
                 return(RedirectToAction("Index", "Home"));
             }
         }
     }
     else
     {
         return(PartialView());
     }
 }
        public ActionResult Create(ClientCreateVM model)
        {
            string msg = "";

            if (ModelState.IsValid)
            {
                bool success = _cRepo.AddClient(model, out msg);
                if (success)
                {
                    TempData["SuccessMsg"] = msg;
                    return(RedirectToAction("index"));
                }
                else
                {
                    TempData["ErrorMsg"] = msg;
                }
            }
            else
            {
                TempData["ErrorMsg"] = "Client cannot be added at this time.";
            }
            model.StatusList = _sRepo.GetStatusList(Key.ROLE_CLIENT);
            return(View(model));
        }