public ActionResult ChangePassword(FormCollection collection)
        {
            if (!IsValidUser(tokens => tokens[1] == Request["username"].ToString()))
            {
                return(RedirectToAction("Logon"));
            }

            DirectSchoolClientClient cc     = new DirectSchoolClientClient();
            DirectSchoolClient       client = cc.GetByRowKey(AuthTokens[3]);

            if (client == null)
            {
                return(RedirectToAction("Logon"));
            }

            if (collection["newpassword"].Trim() == collection["confirmpassword"].Trim())
            {
                client.Password = collection["newpassword"].Trim();
                cc.Update(client);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", new { PasswordError = "Password does not match confirmation" }));
            }
        }
Beispiel #2
0
        public ActionResult Create(DirectSchoolClient newitem)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (newitem.Name == null || newitem.Name == "")
                    {
                        throw new Exception("Client name missing");
                    }
                    if (newitem.ClientId == null)
                    {
                        throw new Exception("ClientId missing");
                    }

                    string clientid = newitem.ClientId.ToUpper().Replace(" ", "");
                    if (clientid == "")
                    {
                        throw new Exception("ClientId cannot be empty");
                    }

                    newitem.ClientId = clientid;

                    DirectSchoolClientClient dscc = new DirectSchoolClientClient();

                    if (dscc.GetByName(newitem.Name) != null)
                    {
                        throw new Exception("A client with this name already exists");
                    }

                    if (dscc.GetByClientId(newitem.ClientId) != null)
                    {
                        throw new Exception("A client with this ClientId already exists");
                    }

                    try
                    {
                        dscc.AddNewItem(newitem);
                        return(RedirectToAction("Index"));
                    }
                    catch
                    {
                        ModelState.AddModelError("error", "Error creating new client");
                    }
                }

                return(View(newitem));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("error", ex.Message);
                return(View(newitem));
            }
        }
Beispiel #3
0
        public ActionResult Edit(string id, DirectSchoolClient item)
        {
            try
            {
                DirectSchoolClientClient dscc = new DirectSchoolClientClient();
                dscc.Update(item);

                //Save LeadCap
                LeadCapClient leadcapclient = new LeadCapClient();
                LeadCap       leadcap       = leadcapclient.GetByRowKey(item.RowKey);
                bool          createnewcap  = false;
                if (leadcap == null)
                {
                    leadcap        = new LeadCap();
                    leadcap.RowKey = item.RowKey;
                    createnewcap   = true;
                }
                leadcap.Total    = item.TotalCap;
                leadcap.Annually = item.AnnualCap;
                leadcap.Monthly  = item.MonthlyCap;
                leadcap.Weekly   = item.WeeklyCap;
                leadcap.Daily    = item.DailyCap;
                if (createnewcap)
                {
                    leadcapclient.AddNewItem(leadcap);
                }
                else
                {
                    leadcapclient.Update(leadcap);
                }

                //Create LeadCounter if doesn't exist
                LeadCounterClient leadcounterclient = new LeadCounterClient();
                LeadCounter       leadcounter       = leadcounterclient.GetByRowKey(item.RowKey);
                if (leadcounter == null)
                {
                    leadcounter          = new LeadCounter();
                    leadcounter.RowKey   = item.RowKey;
                    leadcounter.Total    = 0;
                    leadcounter.Annually = 0;
                    leadcounter.Monthly  = 0;
                    leadcounter.Weekly   = 0;
                    leadcounter.Daily    = 0;
                    leadcounterclient.AddNewItem(leadcounter);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Logon(FormCollection collection)
        {
            DirectSchoolClientClient cc = new DirectSchoolClientClient();

            DirectSchoolClient client = cc.Logon(collection["username"], collection["password"]);

            if (client == null)
            {
                ViewBag.ErrorMessage = "Invalid Username or Password";
                return(View());
            }

            string sessionkey = ClientSession.GetClientSessionKey("school", collection["username"], client.ClientId, client.RowKey);

            Response.Cookies["sessionkey"].Value = sessionkey;
            //Response.Cookies["sessionkey"].Expires = DateTime.UtcNow.AddMinutes(20);

            Response.Cookies["username"].Value = collection["username"];
            //Response.Cookies["username"].Expires = DateTime.UtcNow.AddMinutes(20);


            return(RedirectToAction("Index"));
        }