Esempio n. 1
0
        public ActionResult View(long id, bool createIfNotFound = false)
        {
            var rvm = new ReportViewModel();
            rvm.ID = id;

            using(var c = new DataModelContext())
            {
                Network net = c.Networks
                    .Include("Nodes")
                    .Include("Links")
                    .Include("Orders")
                    .Include("OptimizationResult.Nodes")
                    .Include("OptimizationResult.Links.Link")
                    .Include("OptimizationResult.Links.Link.To")
                    .Include("OptimizationResult.Links.Link.From")
                    .SingleOrDefault(n => n.ID == id);

                if(net.OptimizationResult == null && createIfNotFound)
                {
                    net.Optimize();
                    c.SaveChanges();
                }
                rvm.Report = ReportEngine.getInstance().GenerateReport(net);
            }

            return View(rvm);
        }
Esempio n. 2
0
        public ActionResult Create(FormCollection collection, LoginModel model)
        {
            try
            {
                if(ModelState.IsValid && model.PassConfirm.Equals(model.Password))
                {
                    using(DataModelContext ctx = new DataModelContext())
                    {
                        if(model.PermissionCode != "a95e")
                        {
                            ModelState.AddModelError("regResult", "Permission code invalid.");
                            return View("Index", model);
                        }
                        if (ctx.Users.Any(o => o.Username == model.NewUser.Username))
                        {
                            ModelState.AddModelError("regResult", "Username already exists.");
                            return View("Index", model);
                        }
                        else
                        {
                            byte[] salt = GenerateSalt(16);

                            byte[] hash = GenerateSaltedHash(
                                System.Text.Encoding.UTF8.GetBytes(model.Password), salt);

                            ctx.Users.Add(new User()
                            {
                                EmailAddress = model.NewUser.EmailAddress,
                                RealName = model.NewUser.RealName,
                                Username = model.NewUser.Username,
                                LastLogin = System.DateTime.Now,
                                AccessGroup = model.department,
                                PasswordSalt = salt,
                                PasswordHash = hash,
                            });

                            ctx.SaveChanges();
                            FormsAuthentication.SetAuthCookie(model.NewUser.Username, false);

                            return RedirectToAction("Index", "Home");
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("regResult", "Password does not match confirmation.");
                    return View("Index", model);
                }

            }
            catch
            {
                return RedirectToAction("Index", "Home");
            }
        }
Esempio n. 3
0
        private static void ResetTestDatabase()
        {
            using(var c = new DataModelContext())
            {
                c.Database.Delete();

                // Test user.
                User testUser = new User()
                    {
                        Username = "******",
                        RealName = "Admin Team",

                        // Password: test
                        PasswordHash = new byte[]
                        {117, 173, 203, 91, 75, 63, 147, 6, 200, 176, 45, 40, 104, 7, 114, 213,
                        169, 217, 130, 162, 40, 108, 195, 15, 113, 69, 32, 134, 67, 226, 143, 200},

                        PasswordSalt = new byte[]
                        {24, 10, 184, 91, 24, 196, 93, 99, 150, 30, 131, 109, 16, 28, 181, 193},

                        AccessGroup = DataModel.Enum.UserAccessGroup.Administrator,
                        LastLogin = DateTime.Now,
                        EmailAddress = "*****@*****.**",
                    };
                c.Users.Add(testUser);

                //c.Networks.Add(testnet1);
                XDocument doc = XDocument.Load(HttpContext.Current.Server.MapPath(@"\App_Data\MexNewSampleInputs.xml"));
                var xmlE = new XmlEngine();
                var xmlnetwork = xmlE.XmlFileToNetwork(doc);
                xmlnetwork.Name = "Example file network test";
                xmlnetwork.Author = testUser;
                xmlnetwork.LastEdit = DateTime.Now;
                c.Networks.Add(xmlnetwork);

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    foreach(var i in e.EntityValidationErrors)
                    {
                        Console.WriteLine(i.ValidationErrors);
                    }

                }

            }
        }
Esempio n. 4
0
        private static void ResetTestDatabase()
        {
            using(var c = new DataModelContext())
            {
                c.Database.Delete();

                // Test user.
                User testUser = new User()
                    {
                        Username = "******",
                        RealName = "Admin Team",

                        // Password: test
                        PasswordHash = new byte[]
                        {117, 173, 203, 91, 75, 63, 147, 6, 200, 176, 45, 40, 104, 7, 114, 213,
                        169, 217, 130, 162, 40, 108, 195, 15, 113, 69, 32, 134, 67, 226, 143, 200},

                        PasswordSalt = new byte[]
                        {24, 10, 184, 91, 24, 196, 93, 99, 150, 30, 131, 109, 16, 28, 181, 193},

                        //AccessGroup = DataModel.Enum.UserAccessGroup.Administrator,
                        LastLogin = DateTime.Now,
                        EmailAddress = "*****@*****.**",
                    };
                c.Users.Add(testUser);

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    foreach(var i in e.EntityValidationErrors)
                    {
                        Console.WriteLine(i.ValidationErrors);
                    }

                }

            }
        }
Esempio n. 5
0
        public ActionResult Upload(string NetworkName, IEnumerable<HttpPostedFileBase> files)
        {
            var nvm = new NetworkListViewModel();

            IEnumerable<HttpPostedFileBase> someFiles = files;

            var networkDoc = new XDocument();

            if(NetworkName == "")
            {
                ViewBag.UploadAlert = "Enter a network name";

                using (var c = new DataModelContext())
                {
                    nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList();
                }
                return View("Index", nvm);
            }

            try
            {
                networkDoc = XDocument.Load(Request.Files["NetworkFile"].InputStream);
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
                ViewBag.UploadAlert = "You must select a valid xml file";

                using (var c = new DataModelContext())
                {
                    nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList();
                }
                return View("Index", nvm);
            }

            using(var c = new DataModelContext())
            {

                var xmlE = new XmlEngine();
                var xmlnetwork = xmlE.XmlFileToNetwork(networkDoc);

                xmlnetwork.Name = NetworkName;
                xmlnetwork.Author = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext);
                xmlnetwork.LastEdit = DateTime.Now;
                c.Networks.Add(xmlnetwork);

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    foreach(var i in e.EntityValidationErrors)
                    {
                        Console.WriteLine(i.ValidationErrors);
                    }
                    throw e;
                }
                nvm.Networks = c.Networks.Include("Author").Where(n => n.Name != null).ToList();

                ViewBag.NewNetworkID = xmlnetwork.ID;
            }

            ViewBag.Alert = "Network upload successful";
            ViewBag.AlertClass = "alert-success";
            return View("Index", nvm);
        }
Esempio n. 6
0
        public ActionResult TempEdit(long id, int clickTab)
        {
            Network newNetwork;
            int tab = 0;
            tab = clickTab;
            using(var c = new DataModelContext())
            {
                var originalNetwork = c.Networks.Find(id);

                newNetwork = (Network)originalNetwork.Clone();
                newNetwork.Author = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext);
                newNetwork.LastEdit = DateTime.Now;
                newNetwork.Parent = originalNetwork;
                newNetwork.Revision = originalNetwork.Revision + 1;

                c.Networks.Add(newNetwork);
                c.SaveChanges();
            }

            ViewBag.ID = newNetwork.ID;

            return RedirectToAction("View", new { id = newNetwork.ID, tab = tab });
        }
Esempio n. 7
0
        public JsonResult editLink(NetworkViewModel model)
        {
            ICollection<Link> linkArray = new List<Link>();
            killOptimization(model.ID);

            using (var c = new DataModelContext())
            {
                foreach (Link n in c.Networks.Find(model.ID).Links)
                {
                    if (n.ID == model.NewLink.ID)
                    {
                        foreach (Node node in c.Networks.Find(model.ID).Nodes)
                        {
                            if (node.StationCode == model.NewLink.From.StationCode)
                            {

                                n.From = node;
                            }
                            else if (node.StationCode == model.NewLink.To.StationCode)
                            {
                                n.To = node;
                            }
                        }
                        n.FuelAdjustment = model.NewLink.FuelAdjustment;
                        n.Distance = model.NewLink.Distance;
                        n.MaxTrains = model.NewLink.MaxTrains;
                    }
                }

                var net = c.Networks.Find(model.ID);

                net.LastEdit = DateTime.Now;

                c.SaveChanges();
            }
            return Json(new { success = true });
        }
        public ActionResult EditRequired(double PatientShankLength, double PatientThighLength, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;
                patient.ShankLength = PatientShankLength;
                patient.ThighLength = PatientThighLength;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("Report", new { id = patientID });
        }
        public ActionResult CreateBlank(string PatientFirstName, string PatientLastName, 
			DateTime PatientBirthday, string PatientGender, int PatientFeet, int PatientInches,
			double PatientWeight, string PatientDoctor, string PatientArthritisType, 
			string PatientAffectedExtremity, string PatientDeformity, string PatientCity,
			string PatientPhoneNumber, string PatientEmail)
        {
            var nvm = new PatientListViewModel();

            if(PatientFirstName == "")
            {
                ViewBag.UploadAlert = "Enter the patient's first name";

                using (var c = new DataModelContext())
                {
                    nvm.Patients = c.Patients.Include("Therapist").Where(n => n.LastName != null).ToList();
                }
                return View("Index", nvm);
            }

            if (PatientLastName == "")
            {
                ViewBag.UploadAlert = "Enter the patient's last name";

                using (var c = new DataModelContext())
                {
                    nvm.Patients = c.Patients.Include("Therapist").Where(n => n.LastName != null).ToList();
                }
                return View("Index", nvm);
            }

            using(var c = new DataModelContext())
            {
                var patient = new Patient();
                patient.ReportResult = ReportEngine.getInstance().GenerateReport(patient);
                patient.MedProfile = new MedProfile();

                patient.FirstName = PatientFirstName;
                patient.LastName = PatientLastName;
                patient.Therapist = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext);
                patient.LastUpdate = DateTime.Now;
                patient.Start = DateTime.Now;
                patient.Birthday = PatientBirthday;
                patient.Gender = PatientGender;
                patient.Height = (PatientFeet * 12) + PatientInches;
                patient.Weight = PatientWeight;
                patient.Doctor = PatientDoctor;
                patient.ArthritisType = PatientArthritisType;
                patient.AffectedExtremity = PatientAffectedExtremity;
                patient.Deformity = PatientDeformity;
                patient.ShankLength = 0;
                patient.ThighLength = 0;
                patient.PhoneNumber = PatientPhoneNumber;
                patient.Email = PatientEmail;
                patient.City = PatientCity;
                patient.ContactName = "Not entered";
                patient.ContactRelation = "Not entered";
                patient.ContactPhoneNumber = "Not entered";
                patient.ContactEmail = "Not entered";

                DateTime today = DateTime.Today;
                int age = today.Year - PatientBirthday.Year;
                if (PatientBirthday > today.AddYears(-age)) age--;
                patient.Age = age;

                c.Patients.Add(patient);

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    foreach(var i in e.EntityValidationErrors)
                    {
                        Console.WriteLine(i.ValidationErrors);
                    }
                    throw e;
                }
                nvm.Patients = c.Patients.Include("Therapist").Where(n => n.LastName != null).ToList();

                ViewBag.NewPatientID = patient.ID;
            }

            ViewBag.Alert = "Patient upload successful";
            ViewBag.AlertClass = "alert-success";
            return View("Index", nvm);
        }
        public ActionResult EditMedical(string PatientArthritisType, string PatientAffectedExtremity,
			string PatientDeformity, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;
                patient.ArthritisType = PatientArthritisType;
                patient.AffectedExtremity = PatientAffectedExtremity;
                patient.Deformity = PatientDeformity;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID });
        }
Esempio n. 11
0
        public JsonResult editNode(NetworkViewModel model)
        {
            ICollection<Node> nodeArray = new List<Node>();
            killOptimization(model.ID);

            using (var c = new DataModelContext())
            {
                foreach (Node n in c.Networks.Find(model.ID).Nodes)
                {
                    if (n.StationCode == model.NewNode.StationCode)
                    {
                        n.Name = model.NewNode.Name;
                        n.CarCapacity = model.NewNode.CarCapacity;
                        n.Location = model.NewNode.Location;

                    }
                }

                var net = c.Networks.Find(model.ID);
                net.LastEdit = DateTime.Now;

                c.SaveChanges();
            }
            return Json(new { success = true });
        }
Esempio n. 12
0
        public JsonResult addLink(NetworkViewModel model)
        {
            Link newLink = model.NewLink;
            Link newLink2 = model.NewLink;

            Node to = new Node();
            Node from = new Node();

            Node to2 = new Node();
            Node from2 = new Node();
            killOptimization(model.ID);

            using(var c = new DataModelContext())
            {
                foreach(Node n in c.Networks.Find(model.ID).Nodes)
                {

                    if(n.StationCode == model.NewLink.To.StationCode)
                    {

                        to = n;
                    }
                    else if(n.StationCode == model.NewLink.From.StationCode)
                    {
                        from = n;
                    }
                }

                newLink.From = from;
                newLink.To = to;

                try
                {
                    var net = c.Networks.Find(model.ID);
                    net.Links.Add(newLink);
                    net.LastEdit = DateTime.Now;
                }
                catch(Exception e)
                {
                    throw e;
                }
                c.SaveChanges();
            }

            if (!model.IsOneDirectional)
            {
                using (var d = new DataModelContext())
                {

                    foreach (Node n in d.Networks.Find(model.ID).Nodes)
                    {

                        if (n.StationCode == model.NewLink.To.StationCode)
                        {

                            to2 = n;
                        }
                        else if (n.StationCode == model.NewLink.From.StationCode)
                        {
                            from2 = n;
                        }
                    }
                    newLink2.From = to2;
                    newLink2.To = from2;
                    try
                    {
                        var net = d.Networks.Find(model.ID);
                        net.Links.Add(newLink2);
                        net.LastEdit = DateTime.Now;
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                    d.SaveChanges();
                }
            }
            return Json(new { success=true });
        }
Esempio n. 13
0
        public void killOptimization(long id)
        {
            using (var c = new DataModelContext())
            {
                var net = c.Networks
                    .Include("OptimizationResult")
                    .Include("OptimizationResult.Nodes")
                    .Include("OptimizationResult.Links")
                    .Include("OptimizationResult.OptimizedNetwork")
                    .FirstOrDefault(n => n.ID == id);

                if (net.OptimizationResult == null)
                {
                }
                else{
                var opt = net.OptimizationResult;
                net.OptimizationResult.OptimizedNetwork = null;
                net.OptimizationResult = null;

                net.LastEdit = DateTime.Now;
                c.SaveChanges();
                }
            }
        }
Esempio n. 14
0
        public JsonResult ImplementSuggestion(int oid, int id, bool node)
        {
            using(var c = new DataModelContext())
            {
                Optimization opt = c.Optimizations
                        .Include("OptimizedNetwork")
                        .Include("OptimizedNetwork.Links")
                        .Include("OptimizedNetwork.Links.To")
                        .Include("OptimizedNetwork.Links.From")
                        .Include("OptimizedNetwork.Nodes")
                        .FirstOrDefault(o => o.ID == oid);

                if(node)
                {
                    var nodeObj = opt.Nodes.FirstOrDefault(n => n.ID == id);
                    // Assume suggestion exists.
                    nodeObj.Node.CarCapacity += (int)(nodeObj.ExpansionSuggested);
                }
                else
                {
                    var linkObj = opt.Links.FirstOrDefault(n => n.ID == id);
                    // Assume suggestion exists.
                    linkObj.Link.MaxTrains += (int)(linkObj.ExpansionSuggested);
                }
                opt.OutOfDate = true;

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    var eve = e.EntityValidationErrors;
                    throw e;
                }
            }
            return Json(new { success=true }, JsonRequestBehavior.AllowGet);
        }
Esempio n. 15
0
        public JsonResult ImplementAllSuggestions(int oid)
        {
            using(var c = new DataModelContext())
            {
                Optimization opt = c.Optimizations
                        .Include("OptimizedNetwork")
                        .Include("OptimizedNetwork.Links")
                        .Include("OptimizedNetwork.Links.To")
                        .Include("OptimizedNetwork.Links.From")
                        .Include("OptimizedNetwork.Nodes")
                        .FirstOrDefault(o => o.ID == oid);

                foreach(var n in opt.Nodes)
                {
                    n.Node.CarCapacity += (int)(n.ExpansionSuggested);
                }
                foreach(var l in opt.Links)
                {
                    l.Link.MaxTrains += (int)(l.ExpansionSuggested);
                }
                opt.OutOfDate = true;

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    var eve = e.EntityValidationErrors;
                    throw e;
                }
            }
            return Json(new { success=true }, JsonRequestBehavior.AllowGet);
        }
Esempio n. 16
0
        public JsonResult GetOptimization(long id, bool createOptimization = false)
        {
            using(var c = new DataModelContext())
            {
                Network net = c.Networks.Find(id);
                Optimization opt = net.OptimizationResult;

                if(createOptimization)
                {
                    net.Optimize();
                    opt = net.OptimizationResult;
                    opt.OutOfDate = false;
                    c.SaveChanges();
                }
                else if(opt == null)
                {
                    return Json(
                        new {
                            failure=true,
                            failureMessage="The selected network is not optimized."
                        },
                        JsonRequestBehavior.AllowGet);
                }

                return Json(new
                {
                    nodes = opt.Nodes.ToDictionary(
                        n => n.Node.ID.ToString(),
                        n => new
                        {
                            inFlow = n.FlowIn,
                            outFlow = n.FlowOut,
                        }
                    ),
                    links = opt.Links.ToDictionary(
                        l => l.Link.ID.ToString(),
                        l => new
                        {
                            currentTrains = l.CurrentTrains,
                            currentFlow = l.Flow,
                            subscription = l.TrainSubscription()
                        }
                    ),
                    orders = net.Orders.Select(l => new
                    {
                        id = l.ID,
                        xmlID = l.XMLOrderID,
                        fromid = l.Origin.ID,
                        toid = l.Destination.ID,
                        cars = l.Cars,
                        revenue = l.Revenue
                    })
                }, JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 17
0
        public JsonResult editOrder(NetworkViewModel model)
        {
            ICollection<Order> orderArray = new List<Order>();
            killOptimization(model.ID);

            using (var c = new DataModelContext())
            {
                foreach (Order n in c.Networks.Find(model.ID).Orders)
                {
                    if (n.ID == model.NewOrder.ID)
                    {
                        foreach (Node node in c.Networks.Find(model.ID).Nodes)
                        {
                            if (node.StationCode == model.NewOrder.Origin.StationCode)
                            {
                                n.Origin = node;
                            }
                            else if (node.StationCode == model.NewOrder.Destination.StationCode)
                            {
                                n.Destination = node;
                            }
                        }
                        n.Revenue = model.NewOrder.Revenue;
                        n.Cars = model.NewOrder.Cars;
                    }
                }

                var net = c.Networks.Find(model.ID);

                net.LastEdit = DateTime.Now;

                c.SaveChanges();
            }
            return Json(new { success = true });
        }
 public ActionResult Delete(long id)
 {
     using(var c = new DataModelContext())
     {
         var patient = c.Patients.Find(id);
         patient.LastName = null;
         c.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Esempio n. 19
0
        public JsonResult removeLink(NetworkViewModel model)
        {
            killOptimization(model.ID);
            ICollection<Link> linkArray = new List<Link>();

            using(var c = new DataModelContext())
            {
                var net = c.Networks.Find(model.ID);

                foreach(Link l in net.Links)
                {

                    if(l.From.StationCode == model.NewLink.From.StationCode &&
                        l.To.StationCode == model.NewLink.To.StationCode)
                    {
                        linkArray.Add(l);
                    }

                    if (!model.IsOneDirectional)
                    {
                        if (l.To.StationCode == model.NewLink.From.StationCode &&
                            l.From.StationCode == model.NewLink.To.StationCode)
                        {
                            linkArray.Add(l);
                        }
                    }

                }

                foreach(Link l in linkArray)
                {
                    net.Links.Remove(l);
                }

                net.LastEdit = DateTime.Now;
                c.SaveChanges();
            }
            return Json(new { success=true });
        }
Esempio n. 20
0
        public ActionResult editNetwork(NetworkViewModel model)
        {
            killOptimization(model.ID);
            using (var c = new DataModelContext())
            {
                var net = c.Networks.Find(model.ID);

                net.MaxCarsPerTrain = model.MaxCarsPerTrain;
                net.NonFuelCostPerMile = model.NonFuelCostPerMile;
                net.FuelCostPerMile = model.FuelCostPerMile;
                net.CarCostPerMile = model.CarCostPerMile;
                net.OptimizationResult = null;

                net.LastEdit = DateTime.Now;
                c.SaveChanges();

            }
            return Json(new { success = true });
        }
Esempio n. 21
0
        public JsonResult removeNode(NetworkViewModel model)
        {
            ICollection<Node> nodeArray = new List<Node>();
            ICollection<Link> linkArray = new List<Link>();
            ICollection<Order> orderArray = new List<Order>();
            killOptimization(model.ID);

            using(var c = new DataModelContext())
            {
                foreach(Node n in c.Networks.Find(model.ID).Nodes)
                {
                    if(n.StationCode == model.NewNode.StationCode)
                    {
                        nodeArray.Add(n);
                    }
                }
                foreach(Link l in c.Networks.Find(model.ID).Links)
                {

                    if(l.From.StationCode == model.NewNode.StationCode || l.To.StationCode == model.NewNode.StationCode)
                    {
                        linkArray.Add(l);
                    }

                }
                foreach(Order o in c.Networks.Find(model.ID).Orders)
                {

                    if(o.Origin.StationCode == model.NewNode.StationCode || o.Destination.StationCode == model.NewNode.StationCode)
                    {

                        orderArray.Add(o);
                    }
                }

                var net = c.Networks.Find(model.ID);
                foreach(Node n in nodeArray)
                {
                    net.Nodes.Remove(n);
                }

                foreach(Link l in linkArray)
                {
                    net.Links.Remove(l);
                }

                foreach(Order o in orderArray)
                {
                    net.Orders.Remove(o);
                }
                net.LastEdit = DateTime.Now;

                c.SaveChanges();
            }
            return Json(new { success=true });
        }
Esempio n. 22
0
        public JsonResult removeOrder(NetworkViewModel model)
        {
            ICollection<Order> orderArray = new List<Order>();
            killOptimization(model.ID);

            using(var c = new DataModelContext())
            {
                var net = c.Networks
                    .Include("Orders.Origin")
                    .Include("Orders.Destination")
                    .FirstOrDefault(n => n.ID == model.ID);

                foreach(Order o in net.Orders)
                {
                    Order whyistherenoorder = o;
                    if(o.Origin.StationCode == model.NewOrder.Origin.StationCode && o.Destination.StationCode == model.NewOrder.Destination.StationCode)
                    {
                        orderArray.Add(o);
                    }
                }

                foreach(Order o in orderArray)
                {
                    net.Orders.Remove(o);
                }
                net.LastEdit = DateTime.Now;
                c.SaveChanges();
            }
            return Json(new { success=true });
        }
        public ActionResult EditContact(string PatientContactName, string PatientContactRelation, 
			string PatientContactPhoneNumber, string PatientContactEmail, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;
                patient.ContactName = PatientContactName;
                patient.ContactRelation = PatientContactRelation;
                patient.ContactPhoneNumber = PatientContactPhoneNumber;
                patient.ContactEmail = PatientContactEmail;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID });
        }
Esempio n. 24
0
 public ActionResult SaveNetworkAs(NetworkViewModel model)
 {
     using (var c = new DataModelContext())
     {
         var net = c.Networks.Find(model.ID);
         net.Name = model.Name;
         net.LastEdit = DateTime.Now;
         c.SaveChanges();
     }
     return TempEdit(model.ID, 0);
 }
        public ActionResult EditMedicalProfile(string PatientCurrentMeds, string PatientHeartDisease, string PPatientHeartDisease,
			string PatientDiabetes, string PPatientDiabetes, string PatientCancer, 
			string PPatientCancer, string PatientHighBloodPressure, string PPatientHighBloodPressure,
			PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;

                patient.MedProfile.CurrentMeds = new List<string>(
                    PatientCurrentMeds.Split(new string[] { "\r\n" },
                    StringSplitOptions.RemoveEmptyEntries));

                //Setting Current Conditions
                if (PatientHeartDisease == "Current")
                {
                    patient.MedProfile.HeartDisease = true;
                }
                else
                {
                    patient.MedProfile.HeartDisease = false;
                }
                if (PatientDiabetes == "Current")
                {
                    patient.MedProfile.Diabetes = true;
                }
                else
                {
                    patient.MedProfile.Diabetes = false;
                }
                if (PatientCancer == "Current")
                {
                    patient.MedProfile.Cancer = true;
                }
                else
                {
                    patient.MedProfile.Cancer = false;
                }
                if (PatientHighBloodPressure == "Current")
                {
                    patient.MedProfile.HighBloodPressure = true;
                }
                else
                {
                    patient.MedProfile.HighBloodPressure = false;
                }
                //Setting Past Conditions
                if (PPatientHeartDisease == "Past")
                {
                    patient.MedProfile.PHeartDisease = true;
                }
                else
                {
                    patient.MedProfile.PHeartDisease = false;
                }
                if (PPatientDiabetes == "Past")
                {
                    patient.MedProfile.PDiabetes = true;
                }
                else
                {
                    patient.MedProfile.PDiabetes = false;
                }
                if (PPatientCancer == "Past")
                {
                    patient.MedProfile.PCancer = true;
                }
                else
                {
                    patient.MedProfile.PCancer = false;
                }
                if (PPatientHighBloodPressure == "Past")
                {
                    patient.MedProfile.PHighBloodPressure = true;
                }
                else
                {
                    patient.MedProfile.PHighBloodPressure = false;
                }

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID });
        }
Esempio n. 26
0
        public JsonResult SetDefaultExpansionData(
			int id,
			int? maxNodeExp,
			int? nodeCostPer,
			int? maxLinkExp,
			int? linkCostPer)
        {
            using(var c = new DataModelContext())
            {
                var opt = c.Optimizations
                    .Include("OptimizedNetwork")
                    .FirstOrDefault(o => o.ID == id);

                if(maxNodeExp != null)
                    opt.DefaultNodeExpansion.CapacityExpansionMaxPossible = maxNodeExp;
                if(nodeCostPer != null)
                    opt.DefaultNodeExpansion.CapacityExpansionCostPerUnit = nodeCostPer;
                if(maxLinkExp != null)
                    opt.DefaultLinkExpansion.CapacityExpansionMaxPossible = maxLinkExp;
                if(linkCostPer != null)
                    opt.DefaultLinkExpansion.CapacityExpansionCostPerUnit = linkCostPer;

                opt.OutOfDate = true;

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    var eve = e.EntityValidationErrors;
                    throw e;
                }
            }
            return Json(new { success=true }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult EditPatient(DateTime PatientBirthday, string PatientGender, double PatientHeight, 
			double PatientWeight, string PatientDoctor,	string PatientCity, string PatientEmail, string PatientPhoneNumber, 
			PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;

                patient.Birthday = PatientBirthday;
                patient.Gender = PatientGender;
                patient.Height = PatientHeight;
                patient.Weight = PatientWeight;
                patient.Doctor = PatientDoctor;
                patient.City = PatientCity;
                patient.Email = PatientEmail;
                patient.PhoneNumber = PatientPhoneNumber;

                DateTime today = DateTime.Today;
                int age = today.Year - PatientBirthday.Year;
                if (PatientBirthday > today.AddYears(-age)) age--;
                patient.Age = age;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID});
        }
Esempio n. 28
0
        public JsonResult SetExpansionData(int id, int? maxExp, int? costPerCar, bool node)
        {
            using(var c = new DataModelContext())
            {
                Optimization opt;

                ExpansionParameters p;
                if(node)
                {
                    opt = c.Optimizations
                        .Include("OptimizedNetwork")
                        .FirstOrDefault(o => o.Nodes.Count(n => n.ID == id) > 0);
                    p = c.NodesOptimized.Find(id).Expansion;
                }
                else
                {
                    opt = c.Optimizations
                        .Include("OptimizedNetwork")
                        .FirstOrDefault(o => o.Links.Count(n => n.ID == id) > 0);
                    p = c.LinksOptimized.Find(id).Expansion;
                }
                opt.OutOfDate = true;

                // If maxExp is -1, set to null. Otherwise, set to the given value.
                if(maxExp != null)
                    p.CapacityExpansionMaxPossible = maxExp == -1 ? null : maxExp;
                if(costPerCar != null)
                    p.CapacityExpansionCostPerUnit = costPerCar == -1 ? null : costPerCar;

                c.SaveChanges();
            }
            return Json(new { success=true }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Upload(IEnumerable<HttpPostedFileBase> files, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            //HttpFileCollection someFiles = files;
            //IEnumerable<HttpPostedFileBase> someFiles = files;

            //try
            //{
            //	patientDoc = XDocument.Load(Request.Files["PatientFile"].InputStream);
            //}
            //catch (Exception e)
            //{
            //	Console.WriteLine(e.Message);
            //	ViewBag.UploadAlert = "You must select a valid file";
            //}

            using(var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;

                HttpPostedFileBase patientDoc = Request.Files["PatientFile"];
                var fileName = Path.GetFileName(patientDoc.FileName);
                var path = Path.Combine(Server.MapPath("~/Content/excelfiles"), fileName);
                patientDoc.SaveAs(path);

                var ReportE = ReportEngine.getInstance();
                pvm.Report = ReportE.GenerateReport(patient, path);
                patient.ReportResult = pvm.Report;

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    foreach(var i in e.EntityValidationErrors)
                    {
                        Console.WriteLine(i.ValidationErrors);
                    }
                    throw e;
                }
                //nvm.Patients = c.Patients.Include("Therapist").Where(n => n.Name != null).ToList();

                //ViewBag.NewNetworkID = xmlnetwork.ID;

            }

            ViewBag.Alert = "Upload successful";
            ViewBag.AlertClass = "alert-success";

            return RedirectToAction("Report", new { id = patientID });
            //return View("Report", pvm);
        }
Esempio n. 30
0
 public ActionResult Delete(long id)
 {
     using(var c = new DataModelContext())
     {
         var network = c.Networks.Find(id);
         network.Name = null;
         c.SaveChanges();
     }
     return RedirectToAction("Index");
 }