private string GetSecretFromRepo(Guid AppId)
 {
     using (var context = new Repository.RepoContext())
     {
         var app = context.Applications.Where(w => w.ApplicationId == AppId).FirstOrDefault();
         if (app != null)
             return app.AppGeneratedSecret;
         else
             return null; //Did
     }
 }
 //
 // GET: /Navigation/TopNav
 public PartialViewResult _NavbarTop()
 {
     TopNavModel mdl = new TopNavModel();
     Repository.UserProfile profile;
     using(var cxt = new Repository.RepoContext())
     {
         profile = cxt.UserProfiles.Where(w => w.UserName == WebSecurity.CurrentUserName).FirstOrDefault();
     }
     mdl.usersDisplayName = profile.FirstName;
     mdl.canManageUsers = Roles.GetRolesForUser(profile.UserName).Contains(Constants.ROLES_ADMINISTRATOR);
     return PartialView(mdl);
 }
示例#3
0
        private bool IsAppOverLimit(Guid AppId)
        {
            using (var context = new Repository.RepoContext())
            {
                Repository.Application app = context.Applications.Where(w => w.ApplicationId == AppId).FirstOrDefault();
                if (app != null)
                {
                    switch (app.SubscriptionType)
                    {
                    case Common.Constants.API_SUBSCRIPTION_TYPE_NO_LIMIT:
                        app.ApiAccessMetricCurrent++;
                        break;

                    case Common.Constants.API_SUBSCRIPTION_TYPE_DAILY_RESET:
                        if (app.LastDtmAccessed.DayOfYear < DateTime.UtcNow.DayOfYear)
                        {
                            app.ApiAccessMetricCurrent = 1;
                        }
                        else
                        {
                            app.ApiAccessMetricCurrent++;
                        }
                        if (app.ApiAccessMetricCurrent >= app.ApiAccessMetricLimit)
                        {
                            return(true);
                        }
                        break;

                    case Common.Constants.API_SUBSCRIPTION_TYPE_MONTHLY_RESET:
                        if (app.LastDtmAccessed.Month < DateTime.UtcNow.Month)
                        {
                            app.ApiAccessMetricCurrent = 1;
                        }
                        else
                        {
                            app.ApiAccessMetricCurrent++;
                        }

                        if (app.ApiAccessMetricCurrent >= app.ApiAccessMetricLimit)
                        {
                            return(true);
                        }
                        break;
                    }
                    app.LastDtmAccessed = DateTime.UtcNow;
                    context.SaveChanges();
                }
            }
            return(false);
        }
示例#4
0
        //[ValidateAntiForgeryToken]
        public ActionResult ManageProfile()
        {
            Shoelace.Models.UserProfile model = new Shoelace.Models.UserProfile();
            Repository.UserProfile profile;
            using (var cxt = new Repository.RepoContext())
            {
                profile = cxt.UserProfiles.Where(w => w.UserName == WebSecurity.CurrentUserName).FirstOrDefault();
            }
            model.firstName = profile.FirstName;
            model.lastName = profile.LastName;

            model.userId = WebSecurity.CurrentUserId;
            model.userName = WebSecurity.CurrentUserName;
            return View(model);
        }
示例#5
0
 private string GetSecretFromRepo(Guid AppId)
 {
     using (var context = new Repository.RepoContext())
     {
         var app = context.Applications.Where(w => w.ApplicationId == AppId).FirstOrDefault();
         if (app != null)
         {
             return(app.AppGeneratedSecret);
         }
         else
         {
             return(null); //Did
         }
     }
 }
        private bool IsAppOverLimit(Guid AppId)
        {
            using (var context = new Repository.RepoContext())
            {
                Repository.Application app = context.Applications.Where(w => w.ApplicationId == AppId).FirstOrDefault();
                if (app != null)
                {

                    switch (app.SubscriptionType)
                    {
                        case Common.Constants.API_SUBSCRIPTION_TYPE_NO_LIMIT:
                            app.ApiAccessMetricCurrent++;
                            break;
                        case Common.Constants.API_SUBSCRIPTION_TYPE_DAILY_RESET:
                            if (app.LastDtmAccessed.DayOfYear < DateTime.UtcNow.DayOfYear)
                                app.ApiAccessMetricCurrent = 1;
                            else
                                app.ApiAccessMetricCurrent++;
                            if (app.ApiAccessMetricCurrent >= app.ApiAccessMetricLimit)
                                return true;
                            break;
                        case Common.Constants.API_SUBSCRIPTION_TYPE_MONTHLY_RESET:
                            if (app.LastDtmAccessed.Month < DateTime.UtcNow.Month)
                                app.ApiAccessMetricCurrent = 1;
                            else
                                app.ApiAccessMetricCurrent++;

                            if (app.ApiAccessMetricCurrent >= app.ApiAccessMetricLimit)
                                return true;
                            break;

                    }
                    app.LastDtmAccessed = DateTime.UtcNow;
                    context.SaveChanges();
                }
            }
            return false;
        }
示例#7
0
        public List <Contracts.Recipe> GetAllRecipes()
        {
            List <Contracts.Recipe> retval = new List <Contracts.Recipe>();

            using (var context = new Repository.RepoContext())
            {
                List <Repository.SoupRecipe> DbRecipe = context.SoupRecipes.ToList();
                //MAP from DB object to API Contract
                DbRecipe.ForEach(f => {
                    Contracts.Recipe recipe = new Contracts.Recipe()
                    {
                        RecipeId           = f.RecipeId,
                        RecipeName         = f.RecipeName,
                        PrepTime           = f.PrepTime,
                        PrepInstructions   = f.PrepInstructions,
                        NumOfServings      = f.NumOfServings,
                        FinishInstructions = f.FinishInstructions,
                        EquipmentRequired  = f.EquipmentRequired,
                        CookTime           = f.CookTime,
                        CookTemp           = f.CookTemp
                    };
                    foreach (var dbIngredient in f.Ingredients)
                    {
                        recipe.Ingredients.Add(new Contracts.Ingredient()
                        {
                            IngredientId = dbIngredient.IngredientId,
                            Name         = dbIngredient.Name,
                            Quantity     = dbIngredient.Quantity
                        });
                    }

                    retval.Add(recipe);
                });
            }
            return(retval);
        }
示例#8
0
 public JsonResult SaveProfileInfo(Models.UserProfile p)
 {
     Repository.UserProfile profile;
     using (var cxt = new Repository.RepoContext())
     {
         profile = cxt.UserProfiles.Where(w => w.UserName == WebSecurity.CurrentUserName).FirstOrDefault();
         profile.FirstName = p.firstName;
         profile.LastName = p.lastName;
         cxt.SaveChanges();
     }
     return Json(new { success = true });
 }
示例#9
0
        public ActionResult UserList()
        {
            UserListModel mdl = new UserListModel();
            mdl.logedInUserName = WebSecurity.CurrentUserName;
            using (var cxt = new Repository.RepoContext())
            {
                cxt.UserProfiles.ToList().ForEach(f1 => {
                    UserListModel.UserListItem item = new UserListModel.UserListItem()
                    {
                        userId = f1.UserId,
                        userName = f1.UserName,
                        firstName = f1.FirstName,
                        lastName = f1.LastName
                    };
                    item.userRoles = new List<UserListModel.UserListItem.UserRole>();
                    Common.Constants.SystemRoles().ForEach(f2 => {
                        item.userRoles.Add(new UserListModel.UserListItem.UserRole()
                        {
                            roleName = f2,
                            roleDisplayName = f2,
                            isMember = Roles.IsUserInRole(f1.UserName, f2)

                        });
                    });
                    mdl.users.Add(item);

                });
            }

            return View(mdl);
        }