Exemple #1
0
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Get Item From Database
            TeamOutOfOfficeItem group = new TeamOutOfOfficeItem();

            group = teamOutOfOfficeItemRepository.GetItem(id);

            //Check Exists
            if (group == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            teamOutOfOfficeItemRepository.EditItemForDisplay(group);

            return(View(group));
        }
Exemple #2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            //Get Item From Database
            TeamOutOfOfficeItem group = new TeamOutOfOfficeItem();

            group = teamOutOfOfficeItemRepository.GetItem(id);

            //Check Exists
            if (group == null)
            {
                ViewData["ActionMethod"] = "EditPost";
                return(View("RecordDoesNotExistError"));
            }
            //Check Access
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                return(View("Error"));
            }

            //Update Model From Form + Validate against DB
            try
            {
                UpdateModel(group);
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            //Database Update
            try
            {
                teamOutOfOfficeItemRepository.Edit(group);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/TeamOutOfOfficeItem.mvc/Edit/" + group.TeamOutOfOfficeItemId.ToString();
                    return(View("VersionError"));
                }
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            return(RedirectToAction("List", new { id = group.TeamOutOfOfficeGroupId }));
        }
        //Add Data From Linked Tables for Display
        public void EditItemForDisplay(TeamOutOfOfficeItem item)
        {
            TeamOutOfOfficeGroupRepository teamOutOfOfficeGroupRepository = new TeamOutOfOfficeGroupRepository();

            //PrimaryTeam (from CSU)
            item.HasPrimaryTeam = false;

            //Get TeamOutOfOfficeGroup
            if (item.TeamOutOfOfficeGroup == null)
            {
                item.TeamOutOfOfficeGroup = teamOutOfOfficeGroupRepository.GetGroup(item.TeamOutOfOfficeGroupId);
            }

            //Check TeamOutOfOfficeGroup Exists
            if (item.TeamOutOfOfficeGroup != null)
            {
                //Populate Hierarchy
                teamOutOfOfficeGroupRepository.EditGroupForDisplay(item.TeamOutOfOfficeGroup);

                //Get Primary Team
                Team primaryTeam = GetTeamOutOfOfficeItemPrimaryTeam(item.TeamOutOfOfficeGroup.HierarchyCode);
                if (primaryTeam != null && primaryTeam.TeamId > 0)
                {
                    item.HasPrimaryTeam = true;
                    item.PrimaryTeam    = primaryTeam;
                }
            }

            //Team 1
            if (item.Team != null)
            {
                item.PrimaryBackupTeam = new TeamOutOfOfficeItemBackupTeam()
                {
                    TeamId   = item.Team.TeamId,
                    TeamName = item.Team.TeamName
                };
            }

            //Team 2
            if (item.Team1 != null)
            {
                item.SecondaryBackupTeam = new TeamOutOfOfficeItemBackupTeam()
                {
                    TeamId   = item.Team1.TeamId,
                    TeamName = item.Team1.TeamName
                };
            }

            //Team 3
            if (item.Team2 != null)
            {
                item.TertiaryBackupTeam = new TeamOutOfOfficeItemBackupTeam()
                {
                    TeamId   = item.Team2.TeamId,
                    TeamName = item.Team2.TeamName
                };
            }
        }
        //Edit Item
        public void Edit(TeamOutOfOfficeItem item)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_UpdateTeamOutOfOfficeItem_v1(
                item.TeamOutOfOfficeGroupId,
                item.PrimaryBackupTeam.TeamId,
                item.SecondaryBackupTeam.TeamId,
                item.TertiaryBackupTeam.TeamId,
                adminUserGuid,
                item.VersionNumber
                );
        }