Пример #1
0
        private void CreateRecord(JsonDataOfUserRecord jsonData, Day dayyyy)
        {
            using (ApplicationContext context = new ApplicationContext())
            {
                UserRecord userRecord = new UserRecord();
                userRecord.Rank  = jsonData.Rank;
                userRecord.Steps = jsonData.Steps;

                var statuses = context.UserStatuses.ToList();
                foreach (UserStatus status in statuses)
                {
                    if (status.Description == jsonData.Status)
                    {
                        userRecord.UserStatus = status;
                        break;
                    }
                }

                var users = context.ApplicationUsers.ToList();
                foreach (ApplicationUser user in users)
                {
                    if (user.Name == jsonData.User)
                    {
                        userRecord.ApplicationUser = user;
                        break;
                    }
                }

                var day = context.Days.ToList().LastOrDefault();
                userRecord.Day = day;
                context.UserRecords.Add(userRecord);
                context.SaveChanges();
            }
        }
Пример #2
0
 private void CreateUserStatus(JsonDataOfUserRecord jsonData)
 {
     using (ApplicationContext context = new ApplicationContext())
     {
         UserStatus status = new UserStatus()
         {
             Description = jsonData.Status
         };
         context.UserStatuses.Add(status);
         context.SaveChanges();
     }
 }
Пример #3
0
 private void CreateUser(JsonDataOfUserRecord jsonData)
 {
     using (ApplicationContext context = new ApplicationContext())
     {
         ApplicationUser user = new ApplicationUser()
         {
             Name = jsonData.User
         };
         context.ApplicationUsers.Add(user);
         context.SaveChanges();
     }
 }
Пример #4
0
        private void CheckUserNameAndStatus(JsonDataOfUserRecord jsonData)
        {
            using (ApplicationContext context = new ApplicationContext())
            {
                if (FindStatusByDescription(jsonData.Status) == null)
                {
                    CreateUserStatus(jsonData);
                }

                if (FindUserByName(jsonData.User) == null)
                {
                    CreateUser(jsonData);
                }
            }
        }