Пример #1
0
        public ActionResult Index()
        {
            if (string.IsNullOrEmpty(Session["Login"] as string))
                return RedirectToAction("Index", "Login");

            ViewBag.Username = Session["Login"];

            Models.CatalogueDBEntities db = new Models.CatalogueDBEntities();

            foreach(Models.User user in db.Users)
            {
                if (string.Compare(user.UserName, Session["Login"].ToString()) == 0) {
                    var catalogues = user.Catalogues;
                    catalogues.OrderBy(s => s.Priority);

                    int currentDay = DateTime.Today.Day;
                    int monthDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                    DateTime day = DateTime.Today;

                    string calendar = "";

                    for (var i = 0; i < monthDays - currentDay; i++) {
                        DateTime date = new DateTime(day.Year, day.Month, currentDay + i);
                        calendar += makeCalendar(date, user);
                    }

                    ViewBag.Calendar = calendar;

                    return View(catalogues.ToList());
                }
            }

            return View();
        }
Пример #2
0
        private string makeCalendar(DateTime time, Models.User user)
        {
            string newString = "<div class='calendarHeader'>";
            DateTimeFormatInfo dateFormat = CultureInfo.CurrentCulture.DateTimeFormat;

            newString +=  dateFormat.GetMonthName(time.Month) + " " + time.Day + "(" + dateFormat.GetAbbreviatedDayName(time.DayOfWeek) + "), " + time.Year + "<br/>";

            bool foundItems = false;

            Models.CatalogueDBEntities db = new Models.CatalogueDBEntities();

            var catalogues = user.Catalogues;

            // Tranverse through the database to find matching items
            // If there are then create a Calendar Item for each matching item.
            foreach (Models.Catalogue cata in catalogues)
            {
                var catalogueItems = cata.CatalogueItems;

                foreach (Models.CatalogueItem item in catalogueItems)
                {
                    if (item.Deadline.Year == time.Year)
                        if (item.Deadline.Month == time.Month)
                            if (item.Deadline.Day == time.Day)
                            {
                                newString += "<div class='calendarItem' onclick=\"location.href='" + Url.Action("Edit", "CatalogueItems" , new { id= item.ItemID}) + "'\">";
                                  newString += item.Title + "</div><br/>";
                                foundItems = true;
                            }
                }

                var subcatalogues = cata.SubCatalogues;

                foreach(Models.SubCatalogue subCata in subcatalogues)
                {
                    var subCataItems = subCata.CatalogueItems;

                    foreach (Models.CatalogueItem item in subCataItems)
                    {
                        if (item.Deadline.Year == time.Year)
                            if (item.Deadline.Month == time.Month)
                                if (item.Deadline.Day == time.Day)
                                {
                                    newString += "<div class='calendarItem' onclick=\"location.href='" + Url.Action("Edit", "CatalogueItems", new { id = item.ItemID }) + "'\">";
                                    newString += item.Title + "</div><br/>";
                                    foundItems = true;
                                }
                    }
                }

            }

            if (foundItems)
                newString += "</div>";
            else
                return "";

            return newString;
        }
Пример #3
0
        public ActionResult Create(UserAccount accountToCreate)
        {
            if (ModelState.IsValid)
            {
                // If the accountToCreate object is valid
                // we'll need to save it in a database
                Catalogue.Models.CatalogueDBEntities userAccounts = new Models.CatalogueDBEntities();
                userAccounts.Database.CreateIfNotExists();

                if (userAccounts.Users.Count <Models.User>() > 0)
                {
                    foreach (Models.User user in userAccounts.Users)
                    {
                        if (string.Compare(accountToCreate.UserName.ToLower(), user.UserName.ToLower()) == 0)
                        {
                            ViewBag.Error = "Username already exists";

                            return(View(accountToCreate));
                        }
                    }
                }

                Models.User newUser = new Models.User();

                newUser.UserName = accountToCreate.UserName;
                newUser.Email    = accountToCreate.Email;
                newUser.UserID   = userAccounts.Users.Count <Models.User>() + 1;

                SHA512 encryption = SHA512CryptoServiceProvider.Create();
                byte[] data       = new byte[accountToCreate.Password.Length];
                byte[] result;

                for (int i = 0; i < accountToCreate.Password.Length; i++)
                {
                    data[i] = (byte)accountToCreate.Password[i];
                }

                result = encryption.ComputeHash(data);

                string newString = "";

                for (int i = 0; i < result.Length; i++)
                {
                    newString += String.Format("{0:X2}", result[i]);
                }

                newUser.Password = newString;

                userAccounts.Users.Add(newUser);
                userAccounts.SaveChanges();

                // After saving we'll redirect the user back to Login's Index page
                return(Redirect("/"));
            }

            // Invalid -- redisplay form with errors
            return(View(accountToCreate));
        }
Пример #4
0
        public ActionResult Index(LoginAccount loginAccount)
        {
            if (ModelState.IsValid)
            {
                // todo: If the loginAccount object is valid
                // Compare to see if the object exists in the database
                Catalogue.Models.CatalogueDBEntities database = new Models.CatalogueDBEntities();

                if (database.Database.Exists())
                {
                    foreach (Models.User user in database.Users)
                    {
                        if (string.Compare(user.UserName.ToLower(), loginAccount.UserName.ToLower()) == 0)
                        {
                            SHA512 encryption = new SHA512Managed();
                            byte[] data       = new byte[loginAccount.Password.Length];
                            byte[] result;
                            string temp = loginAccount.Password;

                            for (int i = 0; i < loginAccount.Password.Length; i++)
                            {
                                data[i] = (byte)loginAccount.Password[i];
                            }

                            result = encryption.ComputeHash(data);

                            string newString = "";

                            for (int i = 0; i < result.Length; i++)
                            {
                                newString += String.Format("{0:X2}", result[i]);
                            }

                            loginAccount.Password = newString;

                            if (string.Compare(user.Password, loginAccount.Password) == 0)
                            {
                                Session["Login"]  = user.UserName;
                                Session["UserID"] = user.UserID;
                                return(RedirectToAction("Index", "Home"));
                            }

                            loginAccount.Password = temp;
                        }
                    }
                }
            }

            ViewBag.Error = "Invalid Login / Password";

            return(View(loginAccount));
        }
Пример #5
0
        public ActionResult Create(UserAccount accountToCreate)
        {
            if (ModelState.IsValid)
            {
                // If the accountToCreate object is valid
                // we'll need to save it in a database
                Catalogue.Models.CatalogueDBEntities userAccounts = new Models.CatalogueDBEntities();
                userAccounts.Database.CreateIfNotExists();

                if (userAccounts.Users.Count<Models.User>() > 0)
                    foreach( Models.User user in userAccounts.Users)
                    {
                        if(string.Compare(accountToCreate.UserName.ToLower(), user.UserName.ToLower()) == 0)
                        {
                            ViewBag.Error = "Username already exists";

                            return View(accountToCreate);
                        }
                    }

                Models.User newUser = new Models.User();

                newUser.UserName = accountToCreate.UserName;
                newUser.Email = accountToCreate.Email;
                newUser.UserID = userAccounts.Users.Count<Models.User>() + 1;

                SHA512 encryption = SHA512CryptoServiceProvider.Create();
                byte[] data = new byte[accountToCreate.Password.Length];
                byte[] result;

                for(int i = 0; i < accountToCreate.Password.Length; i++)
                    data[i] = (byte)accountToCreate.Password[i];

                result = encryption.ComputeHash(data);

                string newString = "";

                for (int i = 0; i < result.Length; i++)
                    newString += String.Format("{0:X2}", result[i]);

                newUser.Password = newString;

                userAccounts.Users.Add(newUser);
                userAccounts.SaveChanges();

                // After saving we'll redirect the user back to Login's Index page
                return Redirect("/");
            }

            // Invalid -- redisplay form with errors
            return View(accountToCreate);
        }
Пример #6
0
        public ActionResult Index()
        {
            if (string.IsNullOrEmpty(Session["Login"] as string))
                return RedirectToAction("Index", "Login");

            ViewBag.Username = Session["Login"];

            Models.CatalogueDBEntities db = new Models.CatalogueDBEntities();

            foreach(Models.User user in db.Users)
            {
                if (string.Compare(user.UserName, Session["Login"].ToString()) == 0) {
                    var catalogues = user.Catalogues;
                    catalogues.OrderBy(s => s.Priority);

                    return View(catalogues.ToList());
                }
            }

            return View();
        }
Пример #7
0
        public ActionResult Index()
        {
            if (string.IsNullOrEmpty(Session["Login"] as string))
            {
                return(RedirectToAction("Index", "Login"));
            }

            ViewBag.Username = Session["Login"];

            Models.CatalogueDBEntities db = new Models.CatalogueDBEntities();

            foreach (Models.User user in db.Users)
            {
                if (string.Compare(user.UserName, Session["Login"].ToString()) == 0)
                {
                    var catalogues = user.Catalogues;
                    catalogues.OrderBy(s => s.Priority);

                    int      currentDay = DateTime.Today.Day;
                    int      monthDays  = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                    DateTime day        = DateTime.Today;

                    string calendar = "";

                    for (var i = 0; i < monthDays - currentDay; i++)
                    {
                        DateTime date = new DateTime(day.Year, day.Month, currentDay + i);
                        calendar += makeCalendar(date, user);
                    }

                    ViewBag.Calendar = calendar;

                    return(View(catalogues.ToList()));
                }
            }

            return(View());
        }
Пример #8
0
        private string makeCalendar(DateTime time, Models.User user)
        {
            string             newString  = "<div class='calendarHeader'>";
            DateTimeFormatInfo dateFormat = CultureInfo.CurrentCulture.DateTimeFormat;

            newString += dateFormat.GetMonthName(time.Month) + " " + time.Day + "(" + dateFormat.GetAbbreviatedDayName(time.DayOfWeek) + "), " + time.Year + "<br/>";

            bool foundItems = false;

            Models.CatalogueDBEntities db = new Models.CatalogueDBEntities();

            var catalogues = user.Catalogues;


            // Tranverse through the database to find matching items
            // If there are then create a Calendar Item for each matching item.
            foreach (Models.Catalogue cata in catalogues)
            {
                var catalogueItems = cata.CatalogueItems;

                foreach (Models.CatalogueItem item in catalogueItems)
                {
                    if (item.Deadline.Year == time.Year)
                    {
                        if (item.Deadline.Month == time.Month)
                        {
                            if (item.Deadline.Day == time.Day)
                            {
                                newString += "<div class='calendarItem' onclick=\"location.href='" + Url.Action("Edit", "CatalogueItems", new { id = item.ItemID }) + "'\">";
                                newString += item.Title + "</div><br/>";
                                foundItems = true;
                            }
                        }
                    }
                }

                var subcatalogues = cata.SubCatalogues;

                foreach (Models.SubCatalogue subCata in subcatalogues)
                {
                    var subCataItems = subCata.CatalogueItems;

                    foreach (Models.CatalogueItem item in subCataItems)
                    {
                        if (item.Deadline.Year == time.Year)
                        {
                            if (item.Deadline.Month == time.Month)
                            {
                                if (item.Deadline.Day == time.Day)
                                {
                                    newString += "<div class='calendarItem' onclick=\"location.href='" + Url.Action("Edit", "CatalogueItems", new { id = item.ItemID }) + "'\">";
                                    newString += item.Title + "</div><br/>";
                                    foundItems = true;
                                }
                            }
                        }
                    }
                }
            }

            if (foundItems)
            {
                newString += "</div>";
            }
            else
            {
                return("");
            }

            return(newString);
        }
Пример #9
0
        public ActionResult Index(LoginAccount loginAccount)
        {
            if (ModelState.IsValid)
            {
                // todo: If the loginAccount object is valid
                // Compare to see if the object exists in the database
                Catalogue.Models.CatalogueDBEntities database = new Models.CatalogueDBEntities();

                if (database.Database.Exists())
                {
                    foreach( Models.User user in database.Users)
                    {
                        if(string.Compare(user.UserName.ToLower(), loginAccount.UserName.ToLower()) == 0)
                        {
                            SHA512 encryption = new SHA512Managed();
                            byte[] data = new byte[loginAccount.Password.Length];
                            byte[] result;
                            string temp = loginAccount.Password;

                            for (int i = 0; i < loginAccount.Password.Length; i++)
                                data[i] = (byte)loginAccount.Password[i];

                            result = encryption.ComputeHash(data);

                            string newString = "";

                            for (int i = 0; i < result.Length; i++)
                                newString += String.Format("{0:X2}", result[i]);

                            loginAccount.Password = newString;

                            if (string.Compare(user.Password, loginAccount.Password) == 0)
                            {
                                Session["Login"] = user.UserName;
                                Session["UserID"] = user.UserID;
                                return RedirectToAction("Index", "Home");
                            }

                            loginAccount.Password = temp;
                        }
                    }
                }
            }

            ViewBag.Error = "Invalid Login / Password";

            return View(loginAccount);
        }