Beispiel #1
0
        public List <ConsumableMaterialModel> GetAllConsumableMaterial()
        {
            JSONReadWrite reader = new JSONReadWrite();
            var           data   = reader.returnListConsumable();

            return(data);
        }
Beispiel #2
0
        public IActionResult Index(Reservation reservationModel)
        {
            List <Reservation> reservation = new List <Reservation>();
            JSONReadWrite      readWrite   = new JSONReadWrite();

            reservation = JsonConvert.DeserializeObject <List <Reservation> >(readWrite.Read("people.json", "data"));

            Reservation person = reservation.FirstOrDefault(x => x.Id == reservationModel.Id);

            if (person == null)
            {
                reservation.Add(reservationModel);
            }
            else
            {
                int index = reservation.FindIndex(x => x.Id == reservationModel.Id);
                reservation[index] = reservationModel;
            }

            string jSONString = JsonConvert.SerializeObject(reservation);

            readWrite.Write("people.json", "data", jSONString);

            return(Ok());
        }
Beispiel #3
0
        // public IActionResult Post(int id,string name,string surname, List<string> shoes,bool hungry,int age)
        public IActionResult PostPeople(Person personModel)
        {
            List <Person> people    = new List <Person>();
            JSONReadWrite readWrite = new JSONReadWrite();

            people = JsonConvert.DeserializeObject <List <Person> >(readWrite.Read("people.json", "data"));

            // Person personModel = new Person { Id = id, Name = name, Surname = surname, Shoes = shoes, Hungry = hungry, Age = age };
            Person person = people.FirstOrDefault(x => x.Id == personModel.Id);

            if (person == null)
            {
                people.Add(personModel);
            }
            else
            {
                int index = people.FindIndex(x => x.Id == personModel.Id);
                people[index] = personModel;
            }

            string jSONString = JsonConvert.SerializeObject(people);

            readWrite.Write("people.json", "data", jSONString);

            return(Ok());
        }
Beispiel #4
0
        public ActionResult Index(UserLogin model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                JSONReadWrite UM       = new JSONReadWrite();
                string        password = UM.GetUserPassword(model.UserName);

                if (string.IsNullOrEmpty(password))
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                }
                else
                {
                    if (model.PassWord.Equals(password))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, false);
                        return(RedirectToAction("AdminOnly", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The password provided is incorrect.");
                    }
                }
            }
            return(View(model));
        }
Beispiel #5
0
        public IActionResult GetBestDay()
        {
            JSONReadWrite readWrite = new JSONReadWrite();

            string[]      files    = new string[] { "en.1.json", "en.2.json", "en.3.json" };
            List <League> leagues  = new List <League>();
            List <Match>  matches  = new List <Match>();
            List <Match>  bestDays = new List <Match>();

            for (int l = 0; l < 3; l++)
            {
                leagues = JsonConvert.DeserializeObject <List <League> >(readWrite.Read(files[l], "data"));

                for (int j = 0; j < 1; j++)
                {
                    for (int i = 0; i < leagues[j].Matches.Count; i++)
                    {
                        matches.Add(new Match {
                            leagueName = leagues[j].Name, Round = leagues[j].Matches[i].Round, Date = leagues[j].Matches[i].Date, Team1 = leagues[j].Matches[i].Team1, Team2 = leagues[j].Matches[i].Team2, Score = leagues[j].Matches[i].Score
                        });
                    }
                }
                bestDays.AddRange(matches.Where(m => m.Score.Ft[0] + m.Score.Ft[1] == matches.Max(m => m.Score.Ft[0] + m.Score.Ft[1])));
                matches.Clear();
            }

            return(View(bestDays));
        }
        protected void EditProductButtonClick(object sender, EventArgs e)
        {
            int id = int.TryParse(ProductIdField.Value, out int result) ? result : 0;

            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            Product product = products.Where(p => p.ProductId == id).FirstOrDefault();

            if (product == null)
            {
                Response.Redirect("/Views/Products/ProductsPage.aspx");
            }

            product.Title        = ProductNameTextBox.Text;
            product.Description  = ProductDescriptionTextBox.Text;
            product.Category     = products.Select(s => s.Category).Where(c => c.CategoryName == CategoryDropDownList.SelectedValue).FirstOrDefault();
            product.Supplier     = products.Select(s => s.Supplier).Where(s => s.SupplierName == SupplierDropDownList.SelectedValue).FirstOrDefault();
            product.Manufacturer = products.Select(s => s.Manufacturer).Where(m => m.ManufacturerName == ManufacturerDropDownList.SelectedValue).FirstOrDefault();
            product.Price        = decimal.TryParse(PriceTextBox.Text, out decimal priceResult) ? priceResult : 0;

            int index = products.FindIndex(f => f.ProductId == id);

            products[index] = product;

            string jsonWriteString = JsonConvert.SerializeObject(products);

            readWrite.Write("products.json", "Data", jsonWriteString);

            Response.Redirect("/Views/Products/ProductsPage.aspx");
        }
Beispiel #7
0
        public List <ConsumableOutModel> GetAllConsumableOutput()
        {
            JSONReadWrite reader = new JSONReadWrite();
            var           data   = reader.getListComsumableOut();

            return(data);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            var categories    = products.GroupBy(g => g.Category.CategoryId).Select(s => s.FirstOrDefault().Category).ToList();
            var suppliers     = products.GroupBy(g => g.Supplier.SupplierId).Select(s => s.FirstOrDefault().Supplier).ToList();
            var manufacturers = products.GroupBy(g => g.Manufacturer.ManufacturerId).Select(s => s.FirstOrDefault().Manufacturer).ToList();

            CategoryDropDownList.DataSource    = categories;
            CategoryDropDownList.DataTextField = "CategoryName";
            CategoryDropDownList.ID            = "CategoryId";
            CategoryDropDownList.DataBind();

            SupplierDropDownList.DataSource    = suppliers;
            SupplierDropDownList.DataTextField = "SupplierName";
            SupplierDropDownList.ID            = "SupplierId";
            SupplierDropDownList.DataBind();

            ManufacturerDropDownList.DataSource    = manufacturers;
            ManufacturerDropDownList.DataTextField = "ManufacturerName";
            ManufacturerDropDownList.ID            = "ManufacturerId";
            ManufacturerDropDownList.DataBind();
        }
Beispiel #9
0
        public ActionResult AddOrEditConsumable(string id)
        {
            ConsumableMaterialModel emp = new ConsumableMaterialModel();
            JSONReadWrite           ex  = new JSONReadWrite();

            emp = ex.getConsumableById(id);
            return(View(emp));
        }
Beispiel #10
0
        public List <ProductViewModel> GetProductsFromJSON()
        {
            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            return(ProductViewModel.GetProductsViewModel(products));
        }
Beispiel #11
0
        public IActionResult Index()
        {
            List <HomeModel> employee  = new List <HomeModel>();
            JSONReadWrite    readWrite = new JSONReadWrite();

            employee = JsonConvert.DeserializeObject <List <HomeModel> >(readWrite.Read("employee.json", "data"));
            return(View(employee));
        }
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool          authorize = false;
            JSONReadWrite ex        = new JSONReadWrite();

            authorize = ex.IsUserInRole(httpContext.User.Identity.Name);
            return(authorize);
        }
Beispiel #13
0
        public IActionResult People()
        {
            List <Person> people    = new List <Person>();
            JSONReadWrite readWrite = new JSONReadWrite();

            people = JsonConvert.DeserializeObject <List <Person> >(readWrite.Read("People.json", "data"));
            return(Ok(people));
        }
Beispiel #14
0
        public ActionResult AddOrEditConsumable(ConsumableMaterialModel model)
        {
            try
            {
                if (Int32.Parse(model.materialNumberRecipient) > Int32.Parse(model.materialQuantity))
                {
                    return(Json(new { success = false, message = "Value of 領用數量 cannot be greqter than 請購數量" }, JsonRequestBehavior.AllowGet));
                }

                if (Int32.Parse(model.materialGoodNumberReturn) > Int32.Parse(model.materialNumberRecipient))
                {
                    return(Json(new { success = false, message = "Value of 退庫良品數量 cannot be greqter than 領用數量" }, JsonRequestBehavior.AllowGet));
                }
                if (Int32.Parse(model.materialBadNumberReturn) > Int32.Parse(model.materialNumberRecipient))
                {
                    return(Json(new { success = false, message = "Value of 退庫不良數量 cannot be greqter than 領用數量" }, JsonRequestBehavior.AllowGet));
                }

                if (model.ImageUpload != null && model.materialImagePath != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName);
                    string extension = Path.GetExtension(model.ImageUpload.FileName);
                    fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    model.materialImagePath = "~/AppFiles/Images/" + fileName;
                    model.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }
                JSONReadWrite ex = new JSONReadWrite();
                if (!ex.checkCodeExistOrNot(model.materialCode))
                {
                    var result = ex.addNewConsumable(model);
                    if (result)
                    {
                        return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAlll", GetAllConsumableMaterial()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Add new Fail" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    var result = ex.editConsumable(model);
                    if (result)
                    {
                        return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAlll", GetAllConsumableMaterial()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Edit Fail" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #15
0
        public IActionResult Menus()
        {
            var           menus     = VipDataContext.Menus;
            List <Menu>   people    = new List <Menu>();
            JSONReadWrite readWrite = new JSONReadWrite();

            menus = JsonConvert.DeserializeObject <List <Menu> >(readWrite.Read("CafeData.json", "data"));
            return(Ok(menus));
        }
Beispiel #16
0
    public static UnitSaveData LoadUnit(string path)
    {
        string filePath = baseSavePath + "/" + path + ".json";

        if (File.Exists(filePath))
        {
            return(JSONReadWrite.ReadFromJsonFile <UnitSaveData>(filePath));
        }
        return(null);
    }
Beispiel #17
0
    public static ItemContainerSaveData LoadItems(string path)
    {
        string filePath = baseSavePath + "/" + path + ".json";

        if (File.Exists(filePath))
        {
            return(JSONReadWrite.ReadFromJsonFile <ItemContainerSaveData>(filePath));
        }
        else if (File.Exists(firstPlayPathInventory))
        {
            return(JSONReadWrite.ReadFromJsonFile <ItemContainerSaveData>(firstPlayPathInventory));
        }
        return(null);
    }
Beispiel #18
0
        public IActionResult Delete(int id)
        {
            List <HomeModel> employee  = new List <HomeModel>();
            JSONReadWrite    readWrite = new JSONReadWrite();

            employee = JsonConvert.DeserializeObject <List <HomeModel> >(readWrite.Read("employee.json", "data"));
            int index = employee.FindIndex(x => x.Id == id);

            employee.RemoveAt(index);
            string jSONString = JsonConvert.SerializeObject(employee);

            readWrite.Write("employee.json", "data", jSONString);
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #19
0
        public IActionResult GetPeople(int id)
        {
            List <Person> people    = new List <Person>();
            JSONReadWrite readWrite = new JSONReadWrite();

            people = JsonConvert.DeserializeObject <List <Person> >(readWrite.Read("People.json", "data"));
            var person = people.FirstOrDefault(m => m.Id == id);

            if (person == null)
            {
                return(NotFound());
            }

            return(Ok(person));
        }
Beispiel #20
0
    public static Dictionary <string, UnitSaveData> LoadAllEnemyUnits(string path)
    {
        string filePath = Application.streamingAssetsPath + "/" + path + ".json";

        if (File.Exists(filePath))
        {
            return(JSONReadWrite.ReadFromJsonFile <Dictionary <string, UnitSaveData> >(filePath));
        }
        else if (File.Exists(firstPlayPathUnit))
        {
            Debug.Log("First play json used");
            return(JSONReadWrite.ReadFromJsonFile <Dictionary <string, UnitSaveData> >(firstPlayPathUnit));
        }
        return(null);
    }
Beispiel #21
0
        public IActionResult Delete(int id)
        {
            List <Reservation> reservation = new List <Reservation>();
            JSONReadWrite      readWrite   = new JSONReadWrite();

            reservation = JsonConvert.DeserializeObject <List <Reservation> >(readWrite.Read("people.json", "data"));

            int index = reservation.FindIndex(x => x.Id == id);

            reservation.RemoveAt(index);

            string jSONString = JsonConvert.SerializeObject(reservation);

            readWrite.Write("people.json", "data", jSONString);

            return(RedirectToAction("index", "Person"));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = int.TryParse(Request.QueryString["Id"], out int result) ? result : 0;

                JSONReadWrite  readWrite  = new JSONReadWrite();
                string         jsonString = readWrite.Read("products.json", "Data");
                List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

                Product product = products.Where(p => p.ProductId == id).FirstOrDefault();

                if (product == null)
                {
                    Response.Redirect("/Views/Products/ProductsPage.aspx");
                }

                ProductIdField.Value           = product.ProductId.ToString();
                ProductNameTextBox.Text        = product.Title;
                ProductDescriptionTextBox.Text = product.Description;
                PriceTextBox.Text = product.Price.ToString();

                var categories    = products.GroupBy(g => g.Category.CategoryId).Select(s => s.FirstOrDefault().Category).ToList();
                var suppliers     = products.GroupBy(g => g.Supplier.SupplierId).Select(s => s.FirstOrDefault().Supplier).ToList();
                var manufacturers = products.GroupBy(g => g.Manufacturer.ManufacturerId).Select(s => s.FirstOrDefault().Manufacturer).ToList();

                CategoryDropDownList.DataSource    = categories;
                CategoryDropDownList.SelectedValue = product.Category.CategoryName;
                CategoryDropDownList.DataTextField = "CategoryName";
                CategoryDropDownList.DataBind();

                SupplierDropDownList.Items.Add(" ");
                SupplierDropDownList.DataSource    = suppliers;
                SupplierDropDownList.SelectedValue = product.Supplier.SupplierName;
                SupplierDropDownList.DataTextField = "SupplierName";
                SupplierDropDownList.DataBind();

                ManufacturerDropDownList.DataSource    = manufacturers;
                ManufacturerDropDownList.SelectedValue = product.Manufacturer.ManufacturerName;
                ManufacturerDropDownList.DataTextField = "ManufacturerName";
                ManufacturerDropDownList.DataBind();
            }
        }
Beispiel #23
0
 public ActionResult Delete(string id)
 {
     try
     {
         JSONReadWrite ex     = new JSONReadWrite();
         var           result = ex.deteleMaterialById(id);
         if (result)
         {
             return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAlll", GetAllConsumableMaterial()), message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { success = false, message = "Delete Fail" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #24
0
        public IActionResult Add(HomeModel personModel)
        {
            List <HomeModel> employee  = new List <HomeModel>();
            JSONReadWrite    readWrite = new JSONReadWrite();

            employee = JsonConvert.DeserializeObject <List <HomeModel> >(readWrite.Read("employee.json", "data"));
            HomeModel person = employee.FirstOrDefault(x => x.Id == personModel.Id);

            if (person == null)
            {
                employee.Add(personModel);
            }
            else
            {
                ViewData["Message"] = "Modified data of employee.";
                int index = employee.FindIndex(x => x.Id == personModel.Id);
                employee[index] = personModel;
            }
            string jSONString = JsonConvert.SerializeObject(employee);

            readWrite.Write("employee.json", "data", jSONString);
            return(RedirectToAction("Index", "Home"));
        }
        protected void AddProductButtonClick(object sender, EventArgs e)
        {
            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            Product product = new Product();

            product.ProductId    = products.Count + 1;
            product.Title        = ProductNameTextBox.Text;
            product.Description  = ProductDescriptionTextBox.Text;
            product.Category     = products.Select(s => s.Category).Where(c => c.CategoryName == CategoryDropDownList.SelectedValue).FirstOrDefault();
            product.Supplier     = products.Select(s => s.Supplier).Where(s => s.SupplierName == SupplierDropDownList.SelectedValue).FirstOrDefault();
            product.Manufacturer = products.Select(s => s.Manufacturer).Where(m => m.ManufacturerName == ManufacturerDropDownList.SelectedValue).FirstOrDefault();
            product.Price        = decimal.TryParse(PriceTextBox.Text, out decimal result) ? result : 0;

            products.Add(product);

            string jsonWriteString = JsonConvert.SerializeObject(products);

            readWrite.Write("products.json", "Data", jsonWriteString);

            Response.Redirect("/Views/Products/ProductsPage.aspx");
        }
Beispiel #26
0
 public static void SaveItems(ItemContainerSaveData itemContainerSaveData, string path)
 {
     JSONReadWrite.WriteToJsonFile(baseSavePath + "/" + path + ".json", itemContainerSaveData);
 }
Beispiel #27
0
 public static void SaveUnit(UnitSaveData unitSaveData, string path)
 {
     JSONReadWrite.WriteToJsonFile(baseSavePath + "/" + path + ".json", unitSaveData);
 }
Beispiel #28
0
        public IActionResult GetBestAttackTeam()
        {
            JSONReadWrite readWrite = new JSONReadWrite();

            string[]      files     = new string[] { "en.1.json", "en.2.json", "en.3.json" };
            List <League> leagues   = new List <League>();
            List <Match>  matches   = new List <Match>();
            List <Team>   teams     = new List <Team>();
            List <Team>   bestTeams = new List <Team>();

            for (int l = 0; l < 3; l++)
            {
                leagues = JsonConvert.DeserializeObject <List <League> >(readWrite.Read(files[l], "data"));

                for (int j = 0; j < 1; j++)
                {
                    for (int i = 0; i < leagues[j].Matches.Count; i++)
                    {
                        matches.Add(leagues[j].Matches[i]);
                    }
                }

                foreach (var item in matches)
                {
                    var currentTeam = teams.Find(t => t.Name == item.Team1);
                    if (currentTeam != null)
                    {
                        currentTeam.Goals       += item.Score.Ft[0];
                        currentTeam.MissedGoals += item.Score.Ft[1];
                        currentTeam.LeagueName   = leagues[0].Name;
                    }
                    else
                    {
                        var newTeam = new Team();
                        newTeam.Name        = item.Team1;
                        newTeam.Goals       = item.Score.Ft[0];
                        newTeam.MissedGoals = item.Score.Ft[1];
                        newTeam.LeagueName  = leagues[0].Name;
                        teams.Add(newTeam);
                    }
                }
                foreach (var item in matches)
                {
                    var currentTeam = teams.Find(t => t.Name == item.Team2);
                    if (currentTeam != null)
                    {
                        currentTeam.Goals       += item.Score.Ft[0];
                        currentTeam.MissedGoals += item.Score.Ft[1];
                        currentTeam.LeagueName   = leagues[0].Name;
                    }
                    else
                    {
                        var newTeam = new Team();
                        newTeam.Name        = item.Team1;
                        newTeam.Goals       = item.Score.Ft[1];
                        newTeam.MissedGoals = item.Score.Ft[0];
                        newTeam.LeagueName  = leagues[0].Name;
                        teams.Add(newTeam);
                    }
                }

                bestTeams.AddRange(teams.Where(t => t.Goals == teams.Max(t => t.Goals))
                                   .Select(t => new Team {
                    Name = t.Name, LeagueName = t.LeagueName
                }));
                teams.Clear();
                matches.Clear();
            }
            return(View("GetBestTeam", bestTeams));
        }
Beispiel #29
0
 public static void SaveAllUnits(Dictionary <string, UnitSaveData> allUnitSaveData, string path)
 {
     JSONReadWrite.WriteToJsonFile(baseSavePath + "/" + path + ".json", allUnitSaveData);
 }
        //public bool isValidUser { get; set; }

        public AccountController()
        {
            json  = new JSONReadWrite();
            users = new List <User>();
            users = JsonConvert.DeserializeObject <List <User> >(json.Read("users.json", "./"));
        }