예제 #1
0
        public ActionResult Delete(IEnumerable <type_of_waste> models)
        {
            foreach (var source in models)
            {
                // Create a new Product entity and set its properties from productViewModel
                type_of_waste s = db.type_of_waste.Find(source.id);
                db.type_of_waste.Remove(s);
                db.SaveChanges();
            }

            return(Json(null));
        }
예제 #2
0
        public ActionResult Edit(IEnumerable <type_of_waste> models)
        {
            foreach (var source in models)
            {
                // Create a new Product entity and set its properties from productViewModel
                type_of_waste s = db.type_of_waste.Find(source.id);
                s.name            = source.name;
                db.Entry(s).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(Json(null));
        }
예제 #3
0
        public ActionResult Create(IEnumerable <type_of_waste> models)
        {
            List <TypeWasteWrapper> ss = new List <TypeWasteWrapper>();

            //Iterate all created products which are posted by the Kendo Grid
            foreach (var source in models)
            {
                // Create a new Product entity and set its properties from productViewModel
                var s = new type_of_waste
                {
                    name = source.name
                };

                db.type_of_waste.Add(s);
                db.SaveChanges();
                // store the product in the result
                ss.Add(new TypeWasteWrapper {
                    id = s.id, name = s.name
                });
            }
            return(Json(ss.ToList()));
        }
예제 #4
0
        private string saveNonHazardousRecord(List <object> data)
        {
            string err = "";

            try
            {
                DateTime      date    = DateTime.FromOADate(Double.Parse(data[0].ToString()));
                string        name    = data[1].ToString();
                type_of_waste tw      = db.type_of_waste.Where(p => p.name == name).FirstOrDefault();
                int?          id_type = null;
                if (tw == null)
                {
                    err += "Type of waste of " + data[1].ToString() + " not found.";
                }
                else
                {
                    id_type = tw.id;
                }

                double waste_in = 0;
                Double.TryParse(data[2].ToString(), out waste_in);
                double waste_out = 0;
                Double.TryParse(data[3].ToString(), out waste_out);
                CultureInfo provider = CultureInfo.InvariantCulture;
                double      total    = 0;

                List <NonHazardousWasteRecordWrapper> all = db.non_hazardous_record.Where(p => p.date == date).Select(p => new NonHazardousWasteRecordWrapper {
                    id = p.id, waste_in = p.waste_in, waste_out = p.waste_out, id_type = p.id_type, date = p.date
                }).ToList();
                if (all.Count() != 0)
                {
                    total = all.Sum(p => p.waste_in).Value + waste_in;
                    foreach (NonHazardousWasteRecordWrapper a in all)
                    {
                        non_hazardous_record nn = new non_hazardous_record
                        {
                            id           = a.id,
                            date         = a.date,
                            waste_in     = a.waste_in,
                            waste_out    = a.waste_out,
                            id_type      = a.id_type,
                            recycle_rate = a.waste_out / total * 100
                        };
                        db.Entry(nn).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                else
                {
                    total = waste_in;
                }

                var s = new non_hazardous_record
                {
                    date         = date,
                    waste_in     = waste_in,
                    waste_out    = waste_out,
                    id_type      = id_type,
                    recycle_rate = waste_out / total * 100
                };

                db.non_hazardous_record.Add(s);
                db.SaveChanges();
            }
            finally
            {
            }
            return(err);
        }