示例#1
0
        public JsonResult UpdateUserRole(int appId, int memberId, string roleToUpdate)
        {
            if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), appId, Constants.APPLICATION_MEMBER_ROLE_ADMINISTRATOR))
            {
                return(Json(new {
                    Status = "Error",
                    Msg = "You are not a administrator of this app"
                }));
            }

            using (var context = new Repository.BetaDepotContext())
            {
                ApplicationTeamMember membership = context.ApplicationTeamMembers
                                                   .Where(w => w.TeamMemberId == memberId &&
                                                          w.ApplicationId == appId)
                                                   .FirstOrDefault();

                if (membership != null)
                {
                    membership.MemberRole = roleToUpdate.ToUpper();
                }

                context.SaveChanges();
            }
            return(Json(new
            {
                Status = "OK",
                Msg = ""
            }));
        }
示例#2
0
        private static void CreateAndGetApplicationIfNoExists(string Name, string AppIdentifier, string Platform, string CurrentUserName)
        {
            Application app;

            using (var context = new Repository.BetaDepotContext())
            {
                app = context.Applications.Where(w => w.ApplicationIdentifier == AppIdentifier).FirstOrDefault();

                if (app == null)
                {
                    TeamMember member = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault();
                    app = new Application()
                    {
                        ApplicationIdentifier = AppIdentifier,
                        AssignedMembers       = new List <ApplicationTeamMember>()
                        {
                            new ApplicationTeamMember()
                            {
                                TeamMember = member,
                                MemberRole = Common.Constants.APPLICATION_MEMBER_ROLE_ADMINISTRATOR
                            }
                        },
                        Name     = Name,
                        Platform = Platform
                    };
                    context.Applications.Add(app);
                    context.SaveChanges();
                }
            }
        }
示例#3
0
        public JsonResult UpdateUserManagement(Models.PlatformManageAppSettings n)
        {
            try
            {
                string currentUser = User.Identity.GetUserName().ToLower();
                using (var context = new Repository.BetaDepotContext())
                {
                    var membership = context.ApplicationTeamMembers.Where(w => w.TeamMember.UserName.ToUpper() == currentUser.ToUpper() &&
                                                                          w.ApplicationId == n.AppId)
                                     .FirstOrDefault();
                    membership.ReceiveBuildNotifications = n.IsReceivingBuildNotifications;
                    context.SaveChanges();
                }
            }
            catch
            {
                return(Json(new
                {
                    Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR
                }));
            }

            return(Json(new
            {
                Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS
            }));
        }
示例#4
0
        public JsonResult GenerateNewTokenForApp(int id)
        {
            if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
            {
                throw new HttpException(403, "You are not a team member of this app.");
            }
            String token = string.Empty;

            try
            {
                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                    int currentTimestamp       = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    token        = Common.Functions.GenerateMD5Hash(string.Format("apptoken|{0}|{1}", app.ApplicationIdentifier.ToLower(), currentTimestamp));
                    app.AppToken = token;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR }));
            }


            return(Json(new
            {
                Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS,
                AppToken = token
            }
                        ));
        }
        public static ApplicationBuild SaveBuild(string BuildNotes, string FilePath, string CurrentUserName, int environmentId)
        {
            ApplicationBuild retval = null;
            string BuildType = Platforms.Common.GetFilesBuildPlatform(Path.GetFileName(FilePath));
            Guid uniqueBuildId = new Guid(System.IO.Path.GetFileNameWithoutExtension(FilePath));
            if (BuildType.ToUpper() == Constants.BUILD_PLATFORM_ANDROID)
            {
                Platforms.Android.AndroidManifestData data = Platforms.Android.AndroidPackage.GetManifestData(FilePath);
                CreateAndGetApplicationIfNoExists(data.ApplicationName, data.PackageName, Constants.BUILD_PLATFORM_ANDROID, CurrentUserName);

                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.ApplicationBuild buildToSave = new Repository.ApplicationBuild()
                    {
                        AddedDtm = DateTime.UtcNow,
                        Application = context.Applications.Where(w => w.ApplicationIdentifier == data.PackageName).FirstOrDefault(),
                        UniqueIdentifier = uniqueBuildId,
                        Notes = BuildNotes,
                        versionNumber = data.VersionName,
                        versionCode = data.VersionCode,
                        Platform = Constants.BUILD_PLATFORM_ANDROID,
                        AddedBy = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault(),
                        Environment = context.Environments.Where(w => w.Id == environmentId).FirstOrDefault()
                    };
                    context.Builds.Add(buildToSave);
                    context.SaveChanges();
                    retval = buildToSave;
                }


            }
            else if (BuildType.ToUpper() == Constants.BUILD_PLATFORM_IOS)
            {
                Platforms.iOS.iOSBundleData data = Platforms.iOS.iOSBundle.GetIPABundleData(FilePath);
                CreateAndGetApplicationIfNoExists(data.BundleAppName, data.BundleIdentifier, Constants.BUILD_PLATFORM_IOS, CurrentUserName);

                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.ApplicationBuild buildToSave = new Repository.ApplicationBuild()
                    {
                        AddedDtm = DateTime.UtcNow,
                        Application = context.Applications.Where(w => w.ApplicationIdentifier == data.BundleIdentifier).FirstOrDefault(),
                        UniqueIdentifier = Guid.NewGuid(),
                        Notes = BuildNotes,
                        versionNumber = data.BundleVersion,
                        Platform = Constants.BUILD_PLATFORM_IOS,
                        AddedBy = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault(),
                        Environment = context.Environments.Where(w => w.Id == environmentId).FirstOrDefault()
                    };

                    context.Builds.Add(buildToSave);
                    context.SaveChanges();
                    retval = buildToSave;
                }
            }

            return retval;
        }
示例#6
0
        public static ApplicationBuild SaveBuild(string BuildNotes, string FilePath, string CurrentUserName, int environmentId)
        {
            ApplicationBuild retval        = null;
            string           BuildType     = Platforms.Common.GetFilesBuildPlatform(Path.GetFileName(FilePath));
            Guid             uniqueBuildId = new Guid(System.IO.Path.GetFileNameWithoutExtension(FilePath));

            if (BuildType.ToUpper() == Constants.BUILD_PLATFORM_ANDROID)
            {
                Platforms.Android.AndroidManifestData data = Platforms.Android.AndroidPackage.GetManifestData(FilePath);
                CreateAndGetApplicationIfNoExists(data.ApplicationName, data.PackageName, Constants.BUILD_PLATFORM_ANDROID, CurrentUserName);

                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.ApplicationBuild buildToSave = new Repository.ApplicationBuild()
                    {
                        AddedDtm         = DateTime.UtcNow,
                        Application      = context.Applications.Where(w => w.ApplicationIdentifier == data.PackageName).FirstOrDefault(),
                        UniqueIdentifier = uniqueBuildId,
                        Notes            = BuildNotes,
                        versionNumber    = data.VersionName,
                        versionCode      = data.VersionCode,
                        Platform         = Constants.BUILD_PLATFORM_ANDROID,
                        AddedBy          = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault(),
                        Environment      = context.Environments.Where(w => w.Id == environmentId).FirstOrDefault()
                    };
                    context.Builds.Add(buildToSave);
                    context.SaveChanges();
                    retval = buildToSave;
                }
            }
            else if (BuildType.ToUpper() == Constants.BUILD_PLATFORM_IOS)
            {
                Platforms.iOS.iOSBundleData data = Platforms.iOS.iOSBundle.GetIPABundleData(FilePath);
                CreateAndGetApplicationIfNoExists(data.BundleAppName, data.BundleIdentifier, Constants.BUILD_PLATFORM_IOS, CurrentUserName);

                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.ApplicationBuild buildToSave = new Repository.ApplicationBuild()
                    {
                        AddedDtm         = DateTime.UtcNow,
                        Application      = context.Applications.Where(w => w.ApplicationIdentifier == data.BundleIdentifier).FirstOrDefault(),
                        UniqueIdentifier = Guid.NewGuid(),
                        Notes            = BuildNotes,
                        versionNumber    = data.BundleVersion,
                        Platform         = Constants.BUILD_PLATFORM_IOS,
                        AddedBy          = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault(),
                        Environment      = context.Environments.Where(w => w.Id == environmentId).FirstOrDefault()
                    };

                    context.Builds.Add(buildToSave);
                    context.SaveChanges();
                    retval = buildToSave;
                }
            }

            return(retval);
        }
示例#7
0
        public JsonResult ConfigureAppForCI(int id, bool shouldConfigure)
        {
            if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
            {
                throw new HttpException(403, "You are not a team member of this app.");
            }

            Repository.TeamMember CIUser = Repository.Managers.ApplicationMgr.GetSystemCIUser();
            try
            {
                if (shouldConfigure)
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(CIUser.UserName, id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application           app        = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            Repository.ApplicationTeamMember membership = new Repository.ApplicationTeamMember()
                            {
                                TeamMember = CIUser,
                                MemberRole = Common.Constants.APPLICATION_MEMBER_ROLE_CONTINUOUS_INTEGRATION
                            };

                            app.AssignedMembers.Add(membership);
                            context.SaveChanges();
                        }
                    }
                }
                else
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            app.AppToken = null;
                            Repository.ApplicationTeamMember membership = context.ApplicationTeamMembers
                                                                          .Where(w => w.TeamMember.UserName.ToLower() == CIUser.UserName)
                                                                          .FirstOrDefault();

                            app.AssignedMembers.Remove(membership);
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR }));
            }


            return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS }));
        }
示例#8
0
        public ActionResult AcceptInvite(string uHash, string rHash, int appId, string userName)
        {
            string platform = string.Empty;

            if (uHash != null &&
                rHash != null &&
                appId > 0 &&
                userName != null)
            {
                using (var context = new Repository.BetaDepotContext())
                {
                    Application app = context.Applications.Where(w => w.Id == appId).FirstOrDefault();
                    platform = app.Platform;
                    TeamMember member = context.TeamMembers.Where(w => w.UserName == userName).FirstOrDefault();
                    if (app != null && member != null)
                    {
                        if (isUserInviteTokenValid(app.ApplicationIdentifier, userName, uHash))
                        {
                            if (Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(userName, appId))
                            {
                                throw new HttpException(400, "Your invite is invalid.");
                            }

                            string role = getRoleFromRoleInviteToken(app.ApplicationIdentifier, rHash);
                            if (role != null)
                            {
                                ApplicationTeamMember membership = new ApplicationTeamMember()
                                {
                                    TeamMember = member,
                                    MemberRole = role
                                };

                                app.AssignedMembers.Add(membership);
                                context.SaveChanges();
                            }
                            else
                            {
                                throw new HttpException(400, "Your invite is invalid.");
                            }
                        }
                    }
                    else
                    {
                        throw new HttpException(400, "Your invite is invalid.");
                    }
                }
            }


            return(RedirectToAction("Index", "Platform", new { id = platform }));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent : false);

                    var roleresult = UserManager.AddToRole(user.Id, Common.Constants.SYSTEM_ROLE_USER);

                    //Create user as a team member
                    using (var context = new Repository.BetaDepotContext())
                    {
                        var tm = context.TeamMembers.Where(w => w.UserName == model.UserName).FirstOrDefault();
                        if (tm == null)
                        {
                            context.TeamMembers.Add(new Repository.TeamMember()
                            {
                                EmailAddress = model.UserName,
                                UserName     = model.UserName,
                                FirstName    = model.FirstName,
                                LastName     = model.LastName
                            });
                        }
                        else
                        {
                            tm.FirstName    = model.FirstName;
                            tm.LastName     = model.LastName;
                            tm.EmailAddress = model.UserName;
                        }
                        context.SaveChanges();
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#10
0
        public JsonResult GenerateInviteUrl(string email, string assignedRole, int appId)
        {
            string url = "";
            string msg = "OK";
            bool   isAlreadyTeamMember = Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(email, appId);

            if (!isAlreadyTeamMember)
            {
                int TeamMemberId = -1;
                using (var context = new Repository.BetaDepotContext())
                {
                    Application app = context.Applications.Where(w => w.Id == appId).FirstOrDefault();
                    TeamMember  tm  = context.TeamMembers.Where(w => w.UserName == email).FirstOrDefault();
                    if (tm == null)
                    {
                        tm = new TeamMember()
                        {
                            EmailAddress = email,
                            UserName     = email
                        };
                        context.TeamMembers.Add(tm);
                    }
                    context.SaveChanges();
                    TeamMemberId = tm.Id;
                    int    timestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    string uHash     = Common.Functions.GenerateMD5Hash(string.Format("{0}|{1}|{2}", app.ApplicationIdentifier.ToLower(), email.ToLower(), timestamp));
                    string rHash     = Common.Functions.GenerateMD5Hash(string.Format("{0}|{1}|{2}", app.ApplicationIdentifier.ToLower(), assignedRole.ToLower(), timestamp));

                    string baseUrl = Iteedee.BetaDepot.Common.Functions.GetBaseUrl();
                    if (baseUrl == null)
                    {
                        baseUrl = "http://localhost/";
                    }
                    baseUrl = String.Format("{0}{1}", baseUrl, Url.Content("~"));
                    url     = string.Format("{0}Account/InviteRedirect/?uHash={1}&rHash={2}&appId={3}&userName={4}", baseUrl, uHash, rHash, app.Id, Url.Encode(email.ToLower()));
                }
            }
            else
            {
                msg = "Error";
            }

            return(Json(new {
                Msg = msg,
                Url = url
            }));
        }
        public JsonResult GenerateInviteUrl(string email, string assignedRole, int appId)
        {
            string url = "";
            string msg = "OK";
            bool isAlreadyTeamMember = Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(email, appId);
            if(!isAlreadyTeamMember)
            {
                int TeamMemberId = -1;
                using(var context = new Repository.BetaDepotContext())
                {
                    Application app = context.Applications.Where(w => w.Id == appId).FirstOrDefault();
                    TeamMember tm = context.TeamMembers.Where(w => w.UserName == email).FirstOrDefault();
                    if(tm == null)
                    {
                        tm = new TeamMember()
                        {
                            EmailAddress = email,
                            UserName = email
                        };
                        context.TeamMembers.Add(tm);
                    }
                    context.SaveChanges();
                    TeamMemberId = tm.Id;
                    int timestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    string uHash = Common.Functions.GenerateMD5Hash(string.Format("{0}|{1}|{2}", app.ApplicationIdentifier.ToLower(), email.ToLower(), timestamp));
                    string rHash = Common.Functions.GenerateMD5Hash(string.Format("{0}|{1}|{2}", app.ApplicationIdentifier.ToLower(), assignedRole.ToLower(), timestamp));

                    string baseUrl = Iteedee.BetaDepot.Common.Functions.GetBaseUrl();
                    if (baseUrl == null)
                        baseUrl = "http://localhost/";
                    baseUrl = String.Format("{0}{1}", baseUrl, Url.Content("~"));
                    url = string.Format("{0}Account/InviteRedirect/?uHash={1}&rHash={2}&appId={3}&userName={4}", baseUrl, uHash, rHash, app.Id, Url.Encode(email.ToLower()));
                }
            }
            else
                msg = "Error";

            return Json(new {
                Msg = msg,
                Url = url
            });
        }
        private static void CreateAndGetApplicationIfNoExists(string Name, string AppIdentifier, string Platform, string CurrentUserName)
        {
            Application app;
            using(var context = new Repository.BetaDepotContext())
            {
                app = context.Applications.Where(w => w.ApplicationIdentifier == AppIdentifier).FirstOrDefault();

                if (app == null)
                {
                    TeamMember member = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault();
                    app = new Application()
                    {
                        ApplicationIdentifier = AppIdentifier,
                        AssignedMembers = new List<ApplicationTeamMember>(){ 
                           new ApplicationTeamMember()
                           {
                               TeamMember = member,
                               MemberRole = Common.Constants.APPLICATION_MEMBER_ROLE_ADMINISTRATOR
                           }
                        },
                        Name = Name,
                        Platform = Platform
                        
                    };
                    context.Applications.Add(app);
                    context.SaveChanges();
                }

            }
        }
        public JsonResult UpdateUserManagement(Models.PlatformManageAppSettings n)
        {
            try
            {
                string currentUser = User.Identity.GetUserName().ToLower();
                using (var context = new Repository.BetaDepotContext())
                {
                    var membership = context.ApplicationTeamMembers.Where(w => w.TeamMember.UserName.ToUpper() == currentUser.ToUpper()
                                                                                    && w.ApplicationId == n.AppId)
                                                                    .FirstOrDefault();
                    membership.ReceiveBuildNotifications = n.IsReceivingBuildNotifications;
                    context.SaveChanges();
                }
                     
            }  
            catch
            {
                return Json(new
                {
                    Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR
                });
            }

            return Json(new 
            {
                Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS
            });
        }
        public JsonResult ConfigureAppForCI(int id, bool shouldConfigure)
        {
            if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
                throw new HttpException(403, "You are not a team member of this app.");

            Repository.TeamMember CIUser = Repository.Managers.ApplicationMgr.GetSystemCIUser();
            try
            {
                if (shouldConfigure)
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(CIUser.UserName, id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            Repository.ApplicationTeamMember membership = new Repository.ApplicationTeamMember()
                            {
                                TeamMember = CIUser,
                                MemberRole = Common.Constants.APPLICATION_MEMBER_ROLE_CONTINUOUS_INTEGRATION
                            };

                            app.AssignedMembers.Add(membership);
                            context.SaveChanges();
                        }
                    }
                }
                else
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            app.AppToken = null;
                            Repository.ApplicationTeamMember membership = context.ApplicationTeamMembers
                                                                                .Where(w => w.TeamMember.UserName.ToLower() == CIUser.UserName)
                                                                                .FirstOrDefault();

                            app.AssignedMembers.Remove(membership);
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR });
            }


            return Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS });
        }
        public JsonResult GenerateNewTokenForApp(int id)
        {
            if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
                throw new HttpException(403, "You are not a team member of this app.");
            String token = string.Empty;
            try
            {
                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                    int currentTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    token = Common.Functions.GenerateMD5Hash(string.Format("apptoken|{0}|{1}", app.ApplicationIdentifier.ToLower(), currentTimestamp));
                    app.AppToken = token;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR });
            }


            return Json(new 
                {
                    Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS,
                    AppToken = token
                }
            );
        }
        public JsonResult UpdateUserRole(int appId, int memberId, string roleToUpdate)
        {
            if(!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), appId,Constants.APPLICATION_MEMBER_ROLE_ADMINISTRATOR))
            {
                return Json(new {
                    Status = "Error",
                    Msg = "You are not a administrator of this app"
                });
            }

            using(var context = new Repository.BetaDepotContext())
            {

                ApplicationTeamMember membership = context.ApplicationTeamMembers
                                            .Where(w => w.TeamMemberId == memberId
                                                        && w.ApplicationId == appId)
                                            .FirstOrDefault();

                if (membership != null)
                    membership.MemberRole = roleToUpdate.ToUpper();

                context.SaveChanges();
            }
            return Json(new
            {
                Status = "OK",
                Msg = ""
            });

        }
        public ActionResult AcceptInvite(string uHash, string rHash, int appId, string userName)
        {
            string platform = string.Empty;
            if(uHash != null
                && rHash != null
                && appId > 0
                && userName != null)
            {
                using(var context = new Repository.BetaDepotContext())
                {
                    Application app = context.Applications.Where(w => w.Id == appId).FirstOrDefault();
                    platform = app.Platform;
                    TeamMember member = context.TeamMembers.Where(w => w.UserName == userName).FirstOrDefault();
                    if (app != null && member != null)
                    {
                        if(isUserInviteTokenValid(app.ApplicationIdentifier, userName, uHash))
                        {
                            if(Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(userName, appId))
                                throw new HttpException(400, "Your invite is invalid.");

                            string role = getRoleFromRoleInviteToken(app.ApplicationIdentifier, rHash);
                            if(role != null)
                            {
                                

                                ApplicationTeamMember membership =  new ApplicationTeamMember()
                                        {
                                            TeamMember = member,
                                            MemberRole = role
                                        };

                                app.AssignedMembers.Add(membership);
                                context.SaveChanges();
                            }
                            else
                                throw new HttpException(400, "Your invite is invalid.");
                        }
                    }
                    else
                        throw new HttpException(400, "Your invite is invalid.");

                }
            }
            

            return RedirectToAction("Index", "Platform", new { id = platform });

        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    var roleresult = UserManager.AddToRole(user.Id, Common.Constants.SYSTEM_ROLE_USER);

                    //Create user as a team member
                    using (var context = new Repository.BetaDepotContext())
                    {
                        var tm = context.TeamMembers.Where(w => w.UserName == model.UserName).FirstOrDefault();
                        if (tm == null)
                        {
                            context.TeamMembers.Add(new Repository.TeamMember()
                            {
                                EmailAddress = model.UserName,
                                UserName = model.UserName,
                                FirstName = model.FirstName,
                                LastName = model.LastName
                            });
                           
                        }
                        else
                        {
                            tm.FirstName = model.FirstName;
                            tm.LastName = model.LastName;
                            tm.EmailAddress = model.UserName;
                        }
                        context.SaveChanges();
                    }

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }