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);
                    }
                }
            }
        }
 public List<T> GetDataPointsFromDataStoreBySiteNumber(int siteNumber)
 {
     var conn = DbProviderFactories.GetFactory(Provider).CreateConnection();
     conn.ConnectionString = ConnectionString;
     using (var context = new DataModelContext(conn))
     {
         var assembly = Assembly.GetExecutingAssembly();
         using (Stream stream = assembly.GetManifestResourceStream(FilePath))
         using (StreamReader reader = new StreamReader(stream))
         {
             var script = reader.ReadToEnd() + WhereClauseForSiteSearch + siteNumber;
             var dataModels = context.Database.SqlQuery<T>(script);
             return dataModels.ToList();
         }
     }
 }
Esempio n. 3
0
        private LocalizationText GetByKey(string fullKey, bool create = false)
        {
            var localizations = GetLocalizations();
            var text          = localizations.FirstOrDefault(t => t.Key == fullKey);

            if (text == null && create)
            {
                text = new LocalizationText
                {
                    Lang = _lang,
                    Key  = fullKey
                };
                DataModelContext.Set <LocalizationText>().Add(text);
            }
            return(text);
        }
Esempio n. 4
0
        public virtual ActionResult Page()
        {
            var model = GetById <Location>(WebContext.Location.Id);

            SetLocalizationRedirects();
            if (model == null)
            {
                return(HttpNotFound());
            }
            DataModelContext.Entry(model).Collection(x => x.Blocks).Load();
            //var lang = DependencyResolver.Current.GetService<ILocalizationContext>();
            RenderHomePageDb dbf = new RenderHomePageDb();

            WebContext.Location = dbf.RenderModelHome(WebContext.Location, WebContext.Location.Id);
            return(View(WebContext.Location));
        }
Esempio n. 5
0
 public static void ResetIfDirty()
 {
     //ResetTestDatabase();
     try
     {
         using (var ctx = new DataModelContext())
         {
             // Perform a single operation that will likely never change, to trigger the
             // exception if the model has been altered.
             ctx.Users.First(u => true);
         }
     }
     catch (InvalidOperationException)
     {
         ResetTestDatabase();
     }
 }
Esempio n. 6
0
        public void SeedDefaultCustomer(DataModelContext context)
        {
            var customer = new Customer
            {
                ID             = Guid.NewGuid(),
                FirstName      = "Gabriel",
                LastName       = "Le Roux",
                Address        = "254 Dryer Street, Claremont Cape Town, ZA",
                Gender         = true,
                Phone          = "0793352641",
                Email          = "*****@*****.**",
                IsAccountValid = true
            };

            context.Customers.AddOrUpdate(customer);
            context.SaveChanges();
        }
Esempio n. 7
0
        public ActionResult Index()
        {
            var nvm = new PatientListViewModel();

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

            object alertObject;

            if (TempData.TryGetValue("Alert", out alertObject))
            {
                ViewBag.Alert = alertObject;
            }

            return(View(nvm));
        }
Esempio n. 8
0
 public static void SetDBStringValue(string key, string val)
 {
     using (DataModelContext db = new DataModelContext()) {
         var setting = db.Settings.Select("Key = @Key", new { Key = key }).SingleOrDefault();
         if (setting == null)
         {
             setting       = new Setting();
             setting.Key   = key;
             setting.Value = val;
             db.Settings.Insert(setting);
         }
         else
         {
             setting.Value = val;
             db.Settings.Update(setting);
         }
     }
 }
Esempio n. 9
0
        public EntityDef[] GetEntityDefs()
        {
            if (RequestContext.Current.TenantId == Guid.Empty)
            {
                throw new ArgumentNullException("tenantId");
            }

            EntityDef[] result = null;
            try
            {
                DataModelContext.Initialize(RequestContext.Current.TenantId);
                result = MetadataLogic.GetEntityDefs();
            }
            finally
            {
                DataModelContext.Clear();
            }
            return(result);
        }
Esempio n. 10
0
 public void DeleteExportContract(Guid id)
 {
     if (RequestContext.Current.TenantId == Guid.Empty)
     {
         throw new ArgumentNullException("tenantId");
     }
     try
     {
         DataModelContext.Initialize(RequestContext.Current.TenantId);
         ExportLogic.DeleteExportContract(id);
     }
     catch (Exception ex)
     {
         throw new ExportContractExcepiton(ex.Message, ex);
     }
     finally
     {
         DataModelContext.Clear();
     }
 }
Esempio n. 11
0
        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 }));
        }
Esempio n. 12
0
        public ActionResult View(long id, bool createIfNotFound = false)
        {
            var rvm = new ReportViewModel();

            rvm.ID = id;

            using (var c = new DataModelContext())
            {
                Patient net = c.Patients.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. 13
0
        public void DeleteEntityFieldDef(Guid fieldDefId)
        {
            if (RequestContext.Current.TenantId == Guid.Empty)
            {
                throw new ArgumentNullException("tenantId");
            }

            if (fieldDefId == Guid.Empty)
            {
                throw new ArgumentNullException("fieldDefId");
            }
            try
            {
                DataModelContext.Initialize(RequestContext.Current.TenantId);
                MetadataLogic.DeleteEntityFieldDef(fieldDefId);
            }
            finally
            {
                DataModelContext.Clear();
            }
        }
Esempio n. 14
0
        public virtual ActionResult Index()
        {
            var model = GetEntities <Partner>().Include(x => x.Countries).Include(x => x.Logo).Where(x => x.Visibility).ToList();

            if (DataModelContext.Entry(WebContext.Location).State == EntityState.Unchanged)
            {
                DataModelContext.Entry(WebContext.Location).Collection(x => x.Images).Load();
            }

            var countries = model.SelectMany(x => x.Countries).Distinct();

            countries.ToList().ForEach(x => { x.Name = Localize("country.name." + x.Name); });

            foreach (var p in model)
            {
                p.Name = Localize(p.Name);
                p.Url  = Localize(p.Url);
            }

            return(View(model));
        }
Esempio n. 15
0
        public void UpdateEntityDef(Guid entityDefId, string caption)
        {
            if (RequestContext.Current.TenantId == Guid.Empty)
            {
                throw new ArgumentNullException("tenantId");
            }
            if (entityDefId == Guid.Empty)
            {
                throw new ArgumentNullException("entityDefId");
            }

            try
            {
                DataModelContext.Initialize(RequestContext.Current.TenantId);
                MetadataLogic.UpdateEntityDef(entityDefId, caption);
            }
            finally
            {
                DataModelContext.Clear();
            }
        }
Esempio n. 16
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. 17
0
        public ActionResult Index()
        {
            var hvm = new HomeViewModel();

            using (var c = new DataModelContext())
            {
                User currentUser = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext);

                if (currentUser == null)
                {
                    FormsAuthentication.SignOut();
                    return(RedirectToAction("Index", "Account"));
                }

                hvm.Patients = c.Patients.Include("Therapist").Where(n =>
                                                                     n.LastName != null &&
                                                                     n.Therapist.Username == currentUser.Username
                                                                     ).ToList();
            }

            return(View(hvm));
        }
Esempio n. 18
0
        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. 19
0
        public ActionResult EditPatient(DateTime PatientBirthday, string PatientGender, double PatientHeight,
                                        double PatientWeight, string PatientDoctor, string PatientCity, string PatientState, 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.State       = PatientState;
                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. 20
0
 public ShippingExportDC[] FindExportContractList(string numberToMatch, int?status, Guid?owner)
 {
     if (RequestContext.Current.TenantId == Guid.Empty)
     {
         throw new ArgumentNullException("tenantId");
     }
     try
     {
         DataModelContext.Initialize(RequestContext.Current.TenantId);
         return(ExportLogic.FindExportContractList(
                    RequestContext.Current.TenantId,
                    numberToMatch != null?numberToMatch.Trim():string.Empty,
                    status, owner));
     }
     catch (Exception ex)
     {
         throw new ExportContractExcepiton(ex.Message, ex);
     }
     finally
     {
         DataModelContext.Clear();
     }
 }
Esempio n. 21
0
        public EntityDef GetEnityDefByName(string name)
        {
            if (RequestContext.Current.TenantId == Guid.Empty)
            {
                throw new ArgumentNullException("tenantId");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            EntityDef result = null;

            try
            {
                DataModelContext.Initialize(RequestContext.Current.TenantId);
                result = MetadataLogic.GetEnityDefByName(name);
            }
            finally
            {
                DataModelContext.Clear();
            }
            return(result);
        }
Esempio n. 22
0
        protected override void OnEntityEditing(Country entity, FormCollection collection)
        {
            var name = collection["Name"];

            collection.Remove("Name");

            if (name.IsNullOrEmpty())
            {
                ModelState.AddModelError("Name", "Обязательное поле");
                return;
            }

            if (string.IsNullOrEmpty(entity.Name))
            {
                var alias = name.Transliterate().Replace(" ", "");
                entity.Name = alias;
            }

            var text = GetByKey(entity.Name, true);

            text.Value = name;
            DataModelContext.SaveChanges();
        }
Esempio n. 23
0
        public EntityFieldDef GetFieldDefById(Guid fieldId)
        {
            if (RequestContext.Current.TenantId == Guid.Empty)
            {
                throw new ArgumentNullException("tenantId");
            }
            if (fieldId == Guid.Empty)
            {
                throw new ArgumentNullException("fieldId");
            }
            EntityFieldDef result = null;

            try
            {
                DataModelContext.Initialize(RequestContext.Current.TenantId);
                result = MetadataLogic.GetFieldDefById(fieldId);
            }
            finally
            {
                DataModelContext.Clear();
            }
            return(result);
        }
Esempio n. 24
0
        public virtual ActionResult CreateBlock(int entityId)
        {
            var entity          = DataModelContext.Set <T>().First(x => x.Id == entityId);
            var interfaces      = typeof(T).GetInterfaces();
            var blockHolderType = interfaces.FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IHaveBlocksEntity <>));

            if (blockHolderType != null)
            {
                var vm        = (dynamic)entity;
                var blocks    = Enumerable.Cast <IBlockEntity>((IEnumerable)vm.Blocks);
                var blockType = blockHolderType.GetGenericArguments()[0];
                var block     = (IBlockEntity)Activator.CreateInstance(blockType);
                block.Sort = blocks.Select(x => x.Sort).DefaultIfEmpty().Max() + 1;

                DataModelContext.Set(block.GetType()).Add(block);

                AppendBlock(entity, block);

                DataModelContext.SaveChanges();
                return(PartialView(block));
            }
            return(new EmptyResult());
        }
Esempio n. 25
0
        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. 26
0
 public void UpdateExportContract(ShippingExportDC contract)
 {
     if (RequestContext.Current.TenantId == Guid.Empty)
     {
         throw new ArgumentNullException("tenantId");
     }
     if (contract == null || contract.Id == Guid.Empty)
     {
         throw new ArgumentNullException("contract");
     }
     try
     {
         DataModelContext.Initialize(RequestContext.Current.TenantId);
         ExportLogic.UpdateExportContract(contract);
     }
     catch (Exception ex)
     {
         throw new ExportContractExcepiton(ex.Message, ex);
     }
     finally
     {
         DataModelContext.Clear();
     }
 }
Esempio n. 27
0
 public ShippingExportDC GetExportContractById(Guid id)
 {
     if (RequestContext.Current.TenantId == Guid.Empty)
     {
         throw new ArgumentNullException("tenantId");
     }
     if (id == Guid.Empty)
     {
         throw new ArgumentNullException("id");
     }
     try
     {
         DataModelContext.Initialize(RequestContext.Current.TenantId);
         return(ExportLogic.GetExportContractById(id));
     }
     catch (Exception ex)
     {
         throw new ExportContractExcepiton(ex.Message, ex);
     }
     finally
     {
         DataModelContext.Clear();
     }
 }
Esempio n. 28
0
 public bool ContractExists(string number)
 {
     if (RequestContext.Current.TenantId == Guid.Empty)
     {
         throw new ArgumentNullException("tenantId");
     }
     if (string.IsNullOrEmpty(number))
     {
         throw new ArgumentNullException("number");
     }
     try
     {
         DataModelContext.Initialize(RequestContext.Current.TenantId);
         return(ExportLogic.ContractExists(RequestContext.Current.TenantId, number.Trim()));
     }
     catch (Exception ex)
     {
         throw new ExportContractExcepiton(ex.Message, ex);
     }
     finally
     {
         DataModelContext.Clear();
     }
 }
Esempio n. 29
0
        protected override void OnEntityEditing(Partner entity, FormCollection collection)
        {
            var name  = collection["Name"];
            var url   = collection["Url"];
            var alias = collection["Alias"];

            collection.Remove("Name");
            collection.Remove("Url");
            if (string.IsNullOrEmpty(alias))
            {
                if (string.IsNullOrEmpty(name))
                {
                    ModelState.AddModelError("Name", "Введите название партнёра");
                    return;
                }
                alias = name.Transliterate();
            }
            entity.Alias = alias;
            if (string.IsNullOrEmpty(entity.Name))
            {
                entity.Name = NameKey + alias;
            }
            var nameText = GetByKey(entity.Name, true);

            nameText.Value = name;

            if (entity.Url.IsNullOrEmpty())
            {
                entity.Url = UrlKey + alias;
            }
            var urlText = GetByKey(entity.Url, true);

            urlText.Value = url;

            DataModelContext.SaveChanges();
        }
Esempio n. 30
0
        public ActionResult View(long id)
        {
            var nvm = new PatientViewModel();

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(id);
                if (patient == null)
                {
                    TempData["Alert"] = "The selected patient does not exist.";
                    return(RedirectToAction("Index"));
                }

                nvm.ID                 = patient.ID;
                nvm.FirstName          = patient.FirstName;
                nvm.LastName           = patient.LastName;
                nvm.Therapist          = patient.Therapist;
                nvm.Doctor             = patient.Doctor;
                nvm.LastUpdate         = patient.LastUpdate;
                nvm.Start              = patient.Start;
                nvm.Age                = patient.Age;
                nvm.Birthday           = patient.Birthday;
                nvm.Gender             = patient.Gender;
                nvm.Height             = patient.Height;
                nvm.Weight             = patient.Weight;
                nvm.ArthritisType      = patient.ArthritisType;
                nvm.AffectedExtremity  = patient.AffectedExtremity;
                nvm.Deformity          = patient.Deformity;
                nvm.ShankLength        = patient.ShankLength;
                nvm.ThighLength        = patient.ThighLength;
                nvm.Email              = patient.Email;
                nvm.PhoneNumber        = patient.PhoneNumber;
                nvm.City               = patient.City;
                nvm.State              = patient.State;
                nvm.ContactName        = patient.ContactName;
                nvm.ContactRelation    = patient.ContactRelation;
                nvm.ContactPhoneNumber = patient.ContactPhoneNumber;
                nvm.ContactEmail       = patient.ContactEmail;

                nvm.Report     = patient.ReportResult;
                nvm.MedProfile = patient.MedProfile;

                DateTime dateOnly = nvm.Birthday.Date;
                nvm.BirthdayString = dateOnly.ToString("d");

                DateTime dateOnly2 = nvm.Start.Date;
                nvm.StartString = dateOnly2.ToString("d");

                DateTime dateOnly3 = nvm.Birthday.Date;
                nvm.BirthdayHtml = dateOnly3.ToString("yyyy-MM-dd");

                if (patient.ReportResult == null)
                {
                    nvm.OutOfDate = false;
                    //nvm.Optimized = false;
                }
                else
                {
                    nvm.OutOfDate = patient.ReportResult.OutOfDate;
                    //nvm.Optimized = true;
                }
            }

            return(View("View", nvm));
        }