public ActionResult View(int id)
        {
            PolicyMessageGroupItemHotel policyMessageGroupItemHotel = new PolicyMessageGroupItemHotel();

            policyMessageGroupItemHotel = policyMessageGroupItemHotelRepository.GetPolicyMessageGroupItemHotel(id);;

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

            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(policyMessageGroupItemHotel.PolicyGroupId);

            PolicyMessageGroupItemHotelVM policyMessageGroupItemHotelVM = new PolicyMessageGroupItemHotelVM();

            policyMessageGroupItemHotelVM.PolicyGroupName             = policyGroup.PolicyGroupName;
            policyMessageGroupItemHotelVM.PolicyGroupId               = policyGroup.PolicyGroupId;
            policyMessageGroupItemHotelVM.PolicyMessageGroupItemHotel = policyMessageGroupItemHotel;

            //Populate List of PolicyLocations
            PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository();
            SelectList policyLocations = new SelectList(policyLocationRepository.GetAllPolicyLocations().ToList(), "PolicyLocationId", "PolicyLocationName", policyMessageGroupItemHotel.PolicyLocationId);

            policyMessageGroupItemHotelVM.PolicyLocations = policyLocations;

            return(View(policyMessageGroupItemHotelVM));
        }
Esempio n. 2
0
 public PolicyMessageGroupItemHotelVM(PolicyMessageGroupItemHotel policyMessageGroupItemHotel, int policyGroupId, string policyGroupName, IEnumerable <SelectListItem> policyLocations)
 {
     PolicyMessageGroupItemHotel = policyMessageGroupItemHotel;
     PolicyGroupId   = policyGroupId;
     PolicyGroupName = policyGroupName;
     PolicyLocations = policyLocations;
 }
        public void Delete(PolicyMessageGroupItemHotel policyMessageGroupItemHotel)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_DeletePolicyMessageGroupItemHotel_v1(
                policyMessageGroupItemHotel.PolicyMessageGroupItemId,
                adminUserGuid,
                policyMessageGroupItemHotel.VersionNumber
                );
        }
        public ActionResult Delete(int id, FormCollection collection)
        {
            PolicyMessageGroupItemHotel policyMessageGroupItemHotel = new PolicyMessageGroupItemHotel();

            policyMessageGroupItemHotel = policyMessageGroupItemHotelRepository.GetPolicyMessageGroupItemHotel(id);;

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

            int policyGroupId = policyMessageGroupItemHotel.PolicyGroupId;

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroup(policyGroupId))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Delete Item
            try
            {
                policyMessageGroupItemHotel.VersionNumber = Int32.Parse(collection["PolicyMessageGroupItemHotel.VersionNumber"]);
                policyMessageGroupItemHotelRepository.Delete(policyMessageGroupItemHotel);
            }
            catch (SqlException ex)
            {
                //Versioning Error - go to standard versionError page
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/PolicyMessageGroupItemHotel.mvc/Delete/" + policyMessageGroupItemHotel.PolicyMessageGroupItemId.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
            return(RedirectToAction("List", "PolicyMessageGroupItem", new { id = policyGroupId }));
        }
        //Add
        public void Add(PolicyMessageGroupItemHotel policyMessageGroupItemHotel)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertPolicyMessageGroupItemHotel_v1(
                policyMessageGroupItemHotel.PolicyGroupId,
                policyMessageGroupItemHotel.PolicyMessageGroupItemName,
                policyMessageGroupItemHotel.SupplierCode,
                policyMessageGroupItemHotel.EnabledFlag,
                policyMessageGroupItemHotel.EnabledDate,
                policyMessageGroupItemHotel.ExpiryDate,
                policyMessageGroupItemHotel.TravelDateValidFrom,
                policyMessageGroupItemHotel.TravelDateValidTo,
                policyMessageGroupItemHotel.PolicyLocationId,
                adminUserGuid
                );
        }
        public ActionResult Delete(PolicyMessageGroupItemHotelLanguageVM policyMessageGroupItemHotelLanguageVM)
        {
            //Get PolicyMessageGroupItem
            int policyMessageGroupItemId = policyMessageGroupItemHotelLanguageVM.PolicyMessageGroupItemLanguage.PolicyMessageGroupItemId;
            PolicyMessageGroupItemHotel policyMessageGroupItemHotel = new PolicyMessageGroupItemHotel();

            policyMessageGroupItemHotel = policyMessageGroupItemHotelRepository.GetPolicyMessageGroupItemHotel(policyMessageGroupItemId);

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

            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroupMessages(policyMessageGroupItemHotel.PolicyGroupId))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            PolicyMessageGroupItemLanguage policyMessageGroupItemLanguage = new PolicyMessageGroupItemLanguage();

            policyMessageGroupItemLanguage = policyMessageGroupItemHotelLanguageVM.PolicyMessageGroupItemLanguage;

            try
            {
                policyMessageGroupItemLanguageRepository.Delete(policyMessageGroupItemLanguage);
            }
            catch (SqlException ex)
            {
                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", "PolicyMessageGroupItemLanguage", new { id = policyMessageGroupItemHotel.PolicyMessageGroupItemId }));
        }
        public ActionResult Create(int id)
        {
            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(id);;

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

            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroupMessages(id))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            PolicyMessageGroupItemHotelVM policyMessageGroupItemHotelVM = new PolicyMessageGroupItemHotelVM();

            policyMessageGroupItemHotelVM.PolicyGroupName = policyGroup.PolicyGroupName;
            policyMessageGroupItemHotelVM.PolicyGroupId   = policyGroup.PolicyGroupId;

            PolicyMessageGroupItemHotel policyMessageGroupItemHotel = new PolicyMessageGroupItemHotel();

            policyMessageGroupItemHotel.ProductId     = 2; //Hotel
            policyMessageGroupItemHotel.PolicyGroupId = policyGroup.PolicyGroupId;
            policyMessageGroupItemHotelVM.PolicyMessageGroupItemHotel = policyMessageGroupItemHotel;

            //Populate List of PolicyLocations
            PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository();
            SelectList policyLocations = new SelectList(policyLocationRepository.GetAllPolicyLocations().ToList(), "PolicyLocationId", "PolicyLocationName");

            policyMessageGroupItemHotelVM.PolicyLocations = policyLocations;

            return(View(policyMessageGroupItemHotelVM));
        }
        public ActionResult Create(PolicyMessageGroupItemHotelLanguageVM policyMessageGroupItemHotelLanguageVM)
        {
            //Get PolicyMessageGroupItem
            int policyMessageGroupItemId = policyMessageGroupItemHotelLanguageVM.PolicyMessageGroupItemLanguage.PolicyMessageGroupItemId;
            PolicyMessageGroupItemHotel policyMessageGroupItemHotel = new PolicyMessageGroupItemHotel();

            policyMessageGroupItemHotel = policyMessageGroupItemHotelRepository.GetPolicyMessageGroupItemHotel(policyMessageGroupItemId);

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

            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroupMessages(policyMessageGroupItemHotel.PolicyGroupId))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            PolicyMessageGroupItemLanguage policyMessageGroupItemLanguage = new PolicyMessageGroupItemLanguage();

            policyMessageGroupItemLanguage = policyMessageGroupItemHotelLanguageVM.PolicyMessageGroupItemLanguage;

            //Update  Model from Form
            try
            {
                UpdateModel <PolicyMessageGroupItemLanguage>(policyMessageGroupItemLanguage, "PolicyMessageGroupItemLanguage");
            }
            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"));
            }

            try
            {
                var md = new MarkdownDeep.Markdown();
                md.SafeMode  = true;
                md.ExtraMode = true;
                policyMessageGroupItemLanguage.PolicyMessageGroupItemTranslation = md.Transform(policyMessageGroupItemLanguage.PolicyMessageGroupItemTranslationMarkdown);


                policyMessageGroupItemLanguageRepository.Add(policyMessageGroupItemLanguage);
            }
            catch (SqlException ex)
            {
                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", "PolicyMessageGroupItemLanguage", new { id = policyMessageGroupItemHotel.PolicyMessageGroupItemId }));
        }
        public ActionResult Edit(PolicyMessageGroupItemHotelVM policyMessageGroupItemHotelVM)
        {
            int policyGroupId            = policyMessageGroupItemHotelVM.PolicyMessageGroupItemHotel.PolicyGroupId;
            int policyMessageGroupItemId = policyMessageGroupItemHotelVM.PolicyMessageGroupItemHotel.PolicyMessageGroupItemId;

            PolicyGroup policyGroup = new PolicyGroup();

            policyGroup = policyGroupRepository.GetGroup(policyGroupId);;

            PolicyMessageGroupItemHotel policyMessageGroupItemHotel = new PolicyMessageGroupItemHotel();

            policyMessageGroupItemHotel = policyMessageGroupItemHotelRepository.GetPolicyMessageGroupItemHotel(policyMessageGroupItemId);;

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

            //Check AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToPolicyGroupMessages(policyGroupId))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Update Model from Form
            try
            {
                UpdateModel <PolicyMessageGroupItemHotel>(policyMessageGroupItemHotelVM.PolicyMessageGroupItemHotel, "PolicyMessageGroupItemHotel");
            }
            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"));
            }
            try
            {
                policyMessageGroupItemHotelRepository.Edit(policyMessageGroupItemHotelVM.PolicyMessageGroupItemHotel);
            }
            catch (SqlException ex)
            {
                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", "PolicyMessageGroupItem", new { id = policyGroupId }));
        }