Пример #1
0
 public static void SeedAutocomplete(IZippyDatabase context)
 {
     if (!context.Autocomplete.Any())
     {
         RestClient       client = new RestClient("http://rxnav.nlm.nih.gov/REST");
         var              result = client.Get(new RestRequest("displaynames.json"));
         var              rxData = JsonConvert.DeserializeObject <RxNormData>(result.Content);
         HashSet <string> terms  = new HashSet <string>();
         foreach (var term in rxData.displayTermsList.term)
         {
             // Only use the first alphabetic word in each list
             var oneWord = Regex.Match(term, @"^[a-zA-Z][^\s\,]*");
             if (oneWord.Success)
             {
                 var normalizedTerm = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(oneWord.Value.ToLower());
                 if (normalizedTerm.Length <= 80 && !terms.Contains(normalizedTerm))
                 {
                     context.Add(new Autocomplete()
                     {
                         Term = normalizedTerm
                     });
                     terms.Add(normalizedTerm);
                 }
             }
         }
         context.Commit();
     }
 }
        public MedicationModel Post(MedicationModel model)
        {
            if (!dbContext.Cabinets.Any(u => u.Id == model.CabinetId))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            var medication = model.ToDbMedication();

            dbContext.Add(medication);
            dbContext.Commit();
            return(Get(medication.Id));
        }
Пример #3
0
        public CabinetModel Post(CabinetModel model)
        {
            if (!dbContext.Users.Any(u => u.Id == model.UserId))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            var cabinet = model.ToDbCabinet();

            dbContext.Add(cabinet);
            dbContext.Commit();
            return(Get(cabinet.Id));
        }
Пример #4
0
        public UserModel Post(UserModel model)
        {
            if (model == null)
            {
                // null model is just a request to create a new account, since we
                // don't have any user fields this is permitted.
                model = new UserModel();
            }
            var user = model.ToDbUser();

            dbContext.Add(user);
            dbContext.Commit();
            return(Get(user.Id));
        }