Exemple #1
0
        //POST
        public ActionResult AddDeveloper(FormCollection collection)
        {
            var initiative = _initiativeBusiness.GetInitiative(Guid.Parse(collection["InitiativeId"]));

            if (collection["InviteEmail"].Equals(string.Empty))
            {
                TempData["AddDeveloperError"] = "Enter an email adress";
                return(RedirectToAction("Member", new { initiativeId = collection["InitiativeId"] }));
            }
            if (!new EmailAddressAttribute().IsValid(collection["InviteEmail"]))
            {
                TempData["AddDeveloperError"] = "Email adress is wrongly formatted";
                return(RedirectToAction("Member", new { initiativeId = collection["InitiativeId"] }));
            }
            if (initiative.DeveloperRoles.Any(x => x.DeveloperName == collection["InviteEmail"]))
            {
                TempData["AddDeveloperError"] = "This developer is already a member of the initiative";
                return(RedirectToAction("Member", new { initiativeId = collection["InitiativeId"] }));
            }

            initiative.AddDeveloperRolesInvitation(collection["InviteEmail"]);
            _initiativeBusiness.UpdateInitiative(initiative);
            _initiativeBusiness.ConfirmInvitation(initiative.Id, collection["InviteEmail"]);

            return(RedirectToAction("Member", new { initiativeId = collection["InitiativeId"] }));
        }
Exemple #2
0
        public ActionResult RemoveMember(string id, string application, FormCollection collection)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id", "No initiative id provided.");
            }

            var initiative = _initiativeBusiness.GetInitiative(_accountRepository.FindById(User.Identity.GetUserId()).Email, id);

            initiative.RemoveDeveloperRole(application);
            _initiativeBusiness.UpdateInitiative(initiative);

            return(RedirectToAction("Member", "Initiative", new { id = id }));
        }
Exemple #3
0
        public ActionResult Delete(string id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                var user            = _accountRepository.GetUsers().Single(x => x.UserId == id);
                var initiativeHeads = _initiativeBusiness.GetInitiativesByDeveloperOwner(user.UserName);
                var initiatives     = initiativeHeads.Select(initiativeHead => _initiativeBusiness.GetInitiative(initiativeHead.Id)).ToList();

                foreach (var initiative in initiatives)
                {
                    if (initiative.DeveloperRoles.Any(x => (x.DeveloperName == user.UserName) && x.RoleName.Equals(RoleNameConstants.Administrator)))
                    {
                        initiative.DeveloperRoles.Single(x => (x.DeveloperName == user.UserName) && x.RoleName.Equals(RoleNameConstants.Administrator)).RoleName = RoleNameConstants.Deleted;
                        _initiativeBusiness.UpdateInitiative(initiative);
                    }
                }

                _accountRepository.DeleteUser(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemple #4
0
        public ActionResult Edit(ApplicationPropetiesModel model, FormCollection collection)
        {
            var initiative       = _initiativeBusiness.GetInitiative(_accountRepository.FindById(User.Identity.GetUserId()).Email, model.InitiativeId);
            var applicationGroup = initiative.ApplicationGroups.Single(x => x.Applications.Any(y => y.Name == model.ApplicationName));
            var application      = applicationGroup.Applications.Single(x => x.Name == model.ApplicationName);

            application.TicketPrefix = model.TicketPrefix;

            List <IApplicationVersion> versionsToArchive = null;

            //application.KeepLatestVersions = model.AutoArchive ? model.KeepLatestVersions : null;

            if (model.AutoArchive && model.KeepLatestVersions > 0)
            {
                var versions = _applicationVersionBusiness.GetApplicationVersions(application.Id).ToArray();
                versionsToArchive = versions.OrderBy(x => x.Version).Take(versions.Count() - model.KeepLatestVersions.Value).ToList();

                if (versionsToArchive.IsNullOrEmpty()) //No versions to archive, set autoarchive to true
                {
                    application.KeepLatestVersions = model.KeepLatestVersions;
                }
            }
            else
            {
                application.KeepLatestVersions = null;
            }

            if (initiative.ApplicationGroups.Any(x => x.Name == model.ApplicationGroupName))
            {
                if (initiative.ApplicationGroups.Single(x => x.Name == model.ApplicationGroupName).Applications.All(x => x.Name != model.ApplicationName))
                {
                    initiative.ApplicationGroups.Single(x => x.Name == model.ApplicationGroupName).Add(application);
                }
                else
                {
                    _initiativeBusiness.UpdateInitiative(initiative);

                    //Check if versions to archive, if yes inform user
                    if (versionsToArchive.IsNullOrEmpty())
                    {
                        return(RedirectToAction("Details", "Application", new { id = model.InitiativeId, application = model.ApplicationName }));
                    }

                    //return EnableArchive(versionsToArchive);
                    return(RedirectToAction("EnableArchive", "Application", new { applicationId = application.Id, keepLatestVersions = model.KeepLatestVersions }));
                }
            }
            else
            {
                initiative.AddApplicationGroup(new ApplicationGroup(model.ApplicationGroupName, new List <IApplication> {
                    application
                }));
            }

            applicationGroup.Remove(application);
            _initiativeBusiness.UpdateInitiative(initiative);

            //Check if versions to archive, if yes inform user
            if (versionsToArchive.IsNullOrEmpty())
            {
                return(RedirectToAction("Details", "Application", new { id = model.InitiativeId, application = model.ApplicationName }));
            }

            //return EnableArchive(versionsToArchive);
            return(RedirectToAction("EnableArchive", "Application", new { applicationId = application.Id, keepLatestVersions = model.KeepLatestVersions }));
        }