Ejemplo n.º 1
0
        /// <summary>
        /// Switches the company context for the requestor.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult Instance(string id)
        {
            try
            {
                if (!IsLoggedIn)
                {
                    throw Framework.DataContracts.LoginRequiredException.Create(Framework.DataContracts.LoginRequiredReason.Credentials);
                }

                var client = SvcBldr.Hosting();
                Astria.Framework.DataContracts.ExceptionsML bizEx = null;
                var token = client.SwitchContext(id, out bizEx);
                if (bizEx == null)
                {
                    var authCookie = AstriaCookie.SetToken(token, Functions.GetProxyCookieDomain());
                    Response.Cookies.Add(authCookie);
                }
                return(Result(null, bizEx, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex) { return(Result(null, Astria.Framework.DataContracts.ExceptionsML.GetExceptionML(ex), JsonRequestBehavior.AllowGet)); }
        }
Ejemplo n.º 2
0
        private string GetRedirectURL(out Astria.Framework.DataContracts.ExceptionsML bizEx)
        {
            bizEx = null;
            var redirectUrl = "";

            if (!String.IsNullOrEmpty(Request.QueryString[Constants.INSTANCEID]))
            {
                var hostingClient = SvcBldr.Hosting();
                var token         = hostingClient.SwitchContext(Request.QueryString[Constants.INSTANCEID], out bizEx);
                if (bizEx == null)
                {
                    redirectUrl = Url.Content("~/");
                    var authCookie = AstriaCookie.SetToken(token, Functions.GetProxyCookieDomain());
                    Response.Cookies.Add(authCookie);
                    SvcBldr.Token = token;
                }
            }
            if (!String.IsNullOrEmpty(Request.QueryString[Constants.TYPE]) && bizEx == null)
            {
                if (String.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = Url.Content("~/");
                }

                var    type       = (DC.EntityType)Enum.Parse(typeof(DC.EntityType), Request.QueryString[Constants.TYPE], true);
                string typeString = type.ToString();
                switch (type)
                {
                case DC.EntityType.DocumentVersion:
                    typeString = "ver";     // this abbreviation used for DocumentVersion, the most common cache entity
                    goto case Astria.Framework.DataContracts.EntityType.Document;

                case DC.EntityType.Document:
                    var searchClient = SvcBldr.SearchV2();
                    var data         = new Dictionary <Guid, string>();
                    data.Add(new Guid(Request.QueryString[Constants.ENTITYID]), typeString);
                    if (Request.QueryString[Constants.WF_LINK_ACTION] == Constants.WF_UPDATE_DUEDATE)
                    {
                        var      dueDate = Request.QueryString[Constants.DUEDATE];
                        DateTime tempDate;
                        if (!DateTime.TryParse(dueDate, out tempDate))
                        {
                            throw new Exception(Constants.i18n("invalidDueDate"));
                        }
                        UpdateDueDate(new Guid(Request.QueryString[Constants.ENTITYID]), Convert.ToDateTime(dueDate));
                    }
                    var sr = searchClient.SetCachedViewData(data);
                    if (sr.Error == null)
                    {
                        if (!String.IsNullOrEmpty(Request.QueryString[Constants.WF_LINK_ACTION]))
                        {
                            redirectUrl += String.Format("#Retrieve/view/{0}/index/1/page/1/query?{1}={2}", sr.Result, Constants.WF_LINK_ACTION, Request.QueryString[Constants.WF_LINK_ACTION]);
                        }
                        else
                        {
                            redirectUrl += String.Format("#Retrieve/view/{0}/index/1/page/1", sr.Result);
                        }
                    }
                    break;

                case DC.EntityType.Workflow:
                    redirectUrl = String.Format("#Workflow/queues/1/25/DFWfId/asc/wfItems/{0}/{1}", Request.QueryString[Constants.ENTITYID], Request.QueryString[Constants.USERID]);
                    break;

                // direct links to other entities are not currently supported
                default:
                    break;
                }
            }

            return(redirectUrl);
        }