public void Login([DataBind("loginInfo")]LoginInfo loginInfo)
        {
            bool isValid = new UserSvc().IsValidUser(loginInfo.Email, loginInfo.Password);

            if (isValid)
            {
                ApplicationSecurityContext applicationSecurityContext = HttpContext.Application["securityContext"] as ApplicationSecurityContext;
                UserSecurityContext userSecurityContext = new UserSecurityContext(loginInfo.Email, applicationSecurityContext);
                this.Context.Session["userSecurityContext"] = userSecurityContext;
                this.Context.Session["userSecurityPrincipal"] = new Principal(userSecurityContext);
                this.Redirect(loginInfo.RedirectUrl);
                return;
            }

            this.PropertyBag["loginInfo"] = loginInfo;
        }
Exemple #2
0
 public CoreMenus(UserSecurityContext userSecurityContext)
 {
     this.userSecurityContext = userSecurityContext;
 }
Exemple #3
0
 protected override IRoleProvider GetProvider(UserSecurityContext context)
 {
     return(new PostgresRoleProvider(context));
 }
        public void ApproveAccessRequest(Guid accessRequestId, UserSecurityContext context, ApprovalDecisionType approvalActionType = ApprovalDecisionType.Approve)
        {
            AccessRequest request = _accessRequestRepo.GetOne(accessRequestId);

            ApproveAccessRequest(request, context, approvalActionType);
        }
        public void ApproveAccessRequest(Guid personId, Guid organizationId, UserSecurityContext context, ApprovalDecisionType approvalActionType)
        {
            AccessRequest request = _accessRequestRepo.GetPendingAccessRequest(personId, organizationId);

            ApproveAccessRequest(request, context, approvalActionType);
        }
Exemple #6
0
        public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel)
        {
            if (context.Request.Method == "POST")
            {
                if (method.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    Get(user, context, cancel);
                    return;
                }
                else if (method.Equals("find", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken token = JsonUtils.GetDataPayload(context.Request);

                        if (token["orgid"] != null && token["name"] != null)
                        {
                            GetOrgAndName(JsonUtils.ToId(token["orgid"]), token["name"].ToString(), user, context, cancel);
                            return;
                        }
                        else if (token["name"] != null)
                        {
                            GetName(token["name"].ToString(), user, context, cancel);
                            return;
                        }
                        else if (token["orgid"] != null)
                        {
                            CompoundIdentity cid = JsonUtils.ToId(token["orgid"]);
                            GetOrg(cid, user, context, cancel);
                            return;
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("in", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request));
                        if (ids != null)
                        {
                            GetIds(ids, user, context, cancel);
                            return;
                        }
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                }
                else if (method.Equals("create", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        string name = null;
                        string desc = null;

                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        name = token["name"].ToString();
                        OrganizationProviderBase            o        = OrganizationManager.Instance.GetOrganizationProvider(user);
                        OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        if (provider != null && o != null && token != null && !string.IsNullOrEmpty(name))
                        {
                            CompoundIdentity        orgid  = JsonUtils.ToId(token["orgid"]);
                            Organization            org    = o.Get(orgid);
                            OrganizationAliasScheme scheme = null;
                            desc = (token["desc"]) != null ? token["desc"].ToString() : null;

                            //create
                            scheme = provider.Create(org, name, desc);

                            if (scheme != null)
                            {
                                JObject jscheme = Jsonifier.ToJson(scheme);
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jscheme.ToString()));
                                return;
                            }
                        }
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken t = JsonUtils.GetDataPayload(context.Request);
                        HashSet <CompoundIdentity>          cids     = JsonUtils.ToIds(t);
                        OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        if (provider != null && cids != null)
                        {
                            bool result = true;
                            foreach (CompoundIdentity cid in cids)
                            {
                                result &= provider.Delete(cid);
                            }

                            if (result == true)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                return;
                            }
                        }
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("update", StringComparison.OrdinalIgnoreCase))
                {
                    JToken           token = null;
                    CompoundIdentity cid   = null;
                    CompoundIdentity orgid = null;
                    OrganizationAliasSchemeProviderBase provider = null;
                    OrganizationAliasScheme             scheme   = null;
                    string name = null;
                    string desc = null;

                    try
                    {
                        //check for request.body and provider
                        token    = JsonUtils.GetDataPayload(context.Request);
                        provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        if (provider != null && token != null)
                        {
                            //GUID must be provided
                            cid = JsonUtils.ToId(token["id"]);

                            //fetch stored object
                            bool dirty = false;
                            scheme = provider.Get(cid);
                            if (scheme != null)
                            {
                                //## REQUIRED ##

                                //name
                                if (token.SelectToken("name") != null)
                                {
                                    name = token["name"].ToString();
                                    if (!string.IsNullOrEmpty(name))
                                    {
                                        scheme.Name = name;
                                        dirty       = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable
                                        return;
                                    }
                                }

                                //owning org
                                if (token.SelectToken("orgid") != null)
                                {
                                    orgid = JsonUtils.ToId(token["orgid"]);
                                    if (orgid != null)
                                    {
                                        scheme.OwningOrganizationIdentity = orgid;
                                        dirty = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable
                                        return;
                                    }
                                }

                                //## OPTIONALS ##

                                //description
                                if (token.SelectToken("desc") != null)
                                {
                                    desc = (token["desc"] != null) ? token["desc"].ToString() : null;
                                    scheme.Description = desc;
                                    dirty = true;
                                }

                                if (dirty)
                                {
                                    //update
                                    bool result = provider.Update(scheme);
                                    if (result == true)
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                        return;
                                    }
                                }
                                else
                                {
                                    //return ok - no values were modified
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                    return;
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
            }
            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }
Exemple #7
0
 public override void SetContext(UserSecurityContext userSecurityContext)
 {
     this.accessRequestRepo.SetContext(userSecurityContext);
     this.personRepo.SetContext(userSecurityContext);
     base.SetContext(userSecurityContext);
 }
Exemple #8
0
        private static void GetIds(HashSet <CompoundIdentity> ids, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                if (ids.Count == 0)
                {
                    RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    return;
                }

                InstrumentProviderBase provider = InstrumentManager.Instance.GetInstrumentProvider(user);
                InstrumentKnownArchetypeProviderBase archProvider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                if (provider != null && archProvider != null)
                {
                    IEnumerable <Instrument> instruments = provider.Get(ids);
                    JArray jinstruments = new JArray();
                    foreach (Instrument inst in instruments)
                    {
                        IArchetype arch = archProvider.Get(inst.Identity);
                        if (arch != null)
                        {
                            string archetypeString = archProvider.GetArchetypeType(arch.Identity);
                            switch (archetypeString)
                            {
                            case "SimpleTrapDredge":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as SimpleTrapDredge));
                                break;

                            case "StandardMeshNet":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as StandardMeshNet));
                                break;

                            case "StandardPlanktonNet":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as StandardPlanktonNet));
                                break;

                            case "WingedBagNet":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as WingedBagNet));
                                break;
                            }
                        }
                        else  //instrument has no archetype
                        {
                            jinstruments.Add(Jsonifier.ToJson(inst));
                        }
                    }

                    if (jinstruments != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jinstruments.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
 protected override ICredentialStore GetProvider(UserSecurityContext context)
 {
     return(new PgCredentialStore(context));
 }
 internal PgSiteAliasSchemeProvider(UserSecurityContext context) : base(context)
 {
 }
 internal PgVegSurveyProvider(UserSecurityContext context)
 {
     this.Context       = context;
     this.plotBuilder   = new VegPlotTypeBuilder(context);
     this.surveyBuilder = new VegSurveyBuilder(context);
 }
Exemple #12
0
        static void RegisterPermissions(UserSecurityContext context)
        {
            IPermissionProvider perms = AuthorizationManager.Instance.GetPermissionProvider(context);
            Permission          p;

            if (!perms.Exists(ProjectUtils.ProjectCreatePermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Create, "Project"), ProjectUtils.ProjectCreatePermissionId);
                Console.Write("Registering Permission: Create " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectCreatePermissionId));
            }

            if (!perms.Exists(ProjectUtils.ProjectDeletePermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Delete, "Project"), ProjectUtils.ProjectDeletePermissionId);
                Console.Write("Registering Permission: Delete " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectDeletePermissionId));
            }

            if (!perms.Exists(ProjectUtils.ProjectGetPermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Retrive, "Project"), ProjectUtils.ProjectGetPermissionId);
                Console.Write("Registering Permission: Retrive " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectGetPermissionId));
            }

            if (!perms.Exists(ProjectUtils.ProjectUpdatePermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Update, "Project"), ProjectUtils.ProjectUpdatePermissionId);
                Console.Write("Registering Permission: Update " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectUpdatePermissionId));
            }

            if (!perms.Exists(ProjectUtils.ProjectStatusTypeCreatePermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Create, "ProjectStatusType"), ProjectUtils.ProjectStatusTypeCreatePermissionId);
                Console.Write("Registering Permission: Create " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectStatusTypeCreatePermissionId));
            }

            if (!perms.Exists(ProjectUtils.ProjectStatusTypeDeletePermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Delete, "ProjectStatusType"), ProjectUtils.ProjectStatusTypeDeletePermissionId);
                Console.Write("Registering Permission: Delete " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectStatusTypeDeletePermissionId));
            }

            if (!perms.Exists(ProjectUtils.ProjectStatusTypeGetPermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Retrive, "ProjectStatusType"), ProjectUtils.ProjectStatusTypeGetPermissionId);
                Console.Write("Registering Permission: Retrive " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectStatusTypeGetPermissionId));
            }

            if (!perms.Exists(ProjectUtils.ProjectStatusTypeUpdatePermissionId))
            {
                p = new Permission(PermissionUtils.PermissionName(OperationType.Update, "ProjectStatusType"), ProjectUtils.ProjectStatusTypeUpdatePermissionId);
                Console.Write("Registering Permission: Update " + p.Name + " ");
                perms.RegisterPermission(p);
                Console.WriteLine(perms.Exists(ProjectUtils.ProjectStatusTypeUpdatePermissionId));
            }
        }
Exemple #13
0
        static void Main(string[] args)
        {
            ConfigurationManager.Instance.Bootstrap();
            ConfigurationManager.Instance.Initialize();
            ConfigurationManager.Instance.Start();
            Console.WriteLine("Config state: " + ConfigurationManager.Instance.State);

            LogManager.Instance.Bootstrap();
            LogManager.Instance.Initialize();
            LogManager.Instance.Start();
            Console.WriteLine("Log state: " + LogManager.Instance.State);

            AuthorizationManager.Instance.Bootstrap();
            AuthorizationManager.Instance.Initialize();
            AuthorizationManager.Instance.Start();
            Console.WriteLine("Auth state: " + AuthorizationManager.Instance.State);

            LocalSystemUser     usr     = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
            UserSecurityContext context = new UserSecurityContext(usr);

            if (AuthorizationManager.Instance.State == Osrs.Runtime.RunState.Running)
            {
                //RegisterPermissions(context);
                //Grant(context);
            }

            ProjectManager.Instance.Initialize();
            Console.WriteLine("Projects state: " + ProjectManager.Instance.State);
            ProjectManager.Instance.Start();
            Console.WriteLine("Projects state: " + ProjectManager.Instance.State);

            if (ProjectManager.Instance.State == Osrs.Runtime.RunState.Running)
            {
                IProjectStatusTypeProvider statProv = ProjectManager.Instance.GetStatusTypeProvider(context);
                if (statProv != null)
                {
                    IEnumerable <ProjectStatusType> typs = statProv.Get("Active");
                    ProjectStatusType activeStatus       = null;
                    if (typs != null)
                    {
                        foreach (ProjectStatusType cur in typs)
                        {
                            activeStatus = cur;
                        }
                    }
                    if (activeStatus == null)
                    {
                        activeStatus = statProv.Create("Active", "An active project");
                    }


                    IProjectProvider prov = ProjectManager.Instance.GetProvider(context);
                    if (prov != null)
                    {
                        Console.WriteLine("Creating projects");
                        CreateProjs(prov, activeStatus);

                        IEnumerable <Project> projs = prov.Get();
                        foreach (Project p in projs)
                        {
                            Console.WriteLine(p.Name);
                        }
                    }
                }
            }

            Console.WriteLine("ALL COMPLETE - Enter to exit");
            Console.ReadLine();
        }
 protected ProjectStatusTypeProviderBase(UserSecurityContext context)
 {
     this.Context = context;
 }
 protected internal abstract IRoleProvider GetProvider(UserSecurityContext context);
Exemple #16
0
        public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel)
        {
            if (context.Request.Method == "POST")
            {
                if (method.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    Get(user, context, cancel);
                    return;
                }
                else if (method.Equals("in", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request));
                        if (ids != null)
                        {
                            GetIds(ids, user, context, cancel);
                            return;
                        }
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                }
                else if (method.Equals("create", StringComparison.OrdinalIgnoreCase))
                {
                    CompoundIdentity       owner    = null;
                    CompoundIdentity       type     = null;
                    string                 name     = null;
                    string                 desc     = null;
                    string                 serial   = null;
                    CompoundIdentity       manf     = null;
                    InstrumentProviderBase provider = null;
                    InstrumentKnownArchetypeProviderBase archProvider = null;
                    JToken token = null;

                    try
                    {
                        //payload and provider
                        token        = JsonUtils.GetDataPayload(context.Request);
                        provider     = InstrumentManager.Instance.GetInstrumentProvider(user);
                        archProvider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                        if (provider != null && token != null)
                        {
                            //required inputs
                            name  = token["name"].ToString();
                            owner = JsonUtils.ToId(token["orgid"]);
                            type  = JsonUtils.ToId(token["typeid"]);
                            if (owner != null && type != null && !string.IsNullOrEmpty(name))
                            {
                                //optionals
                                desc   = token["desc"] != null ? token["desc"].ToString() : null;
                                serial = token["serial"] != null ? token["serial"].ToString() : null;
                                manf   = JsonUtils.ToId(token["manf"]);

                                //create
                                Instrument instrument = null;
                                instrument = provider.Create(owner, name, type, desc, serial, manf);
                                if (instrument != null)
                                {
                                    JObject jinstrument = null;

                                    //call update to persist architype info
                                    //archid and archdata are expected to be valid and consistent; non-matching properties are ignored
                                    if (token.SelectToken("archid") != null)                                     //JSON property was present
                                    {
                                        CompoundIdentity archid          = JsonUtils.ToId(token["archid"]);
                                        string           archetypeString = archProvider.GetArchetypeType(archid);
                                        JToken           archToken       = token["archdata"];
                                        switch (archetypeString)
                                        {
                                        case "SimpleTrapDredge":
                                            SimpleTrapDredge std = archProvider.AddSimpleTrapDredge(instrument.Identity);
                                            if (archToken["openarea"] != null)
                                            {
                                                std.OpenArea = double.Parse(archToken["openarea"].ToString());
                                            }
                                            archProvider.Update(std);
                                            jinstrument = Jsonifier.ToJson(instrument, std);
                                            break;

                                        case "StandardMeshNet":
                                            StandardMeshNet smn = archProvider.AddStandardMeshNet(instrument.Identity);
                                            if (archToken["length"] != null)
                                            {
                                                smn.Length = double.Parse(archToken["length"].ToString());
                                            }
                                            if (archToken["depth"] != null)
                                            {
                                                smn.Depth = double.Parse(archToken["depth"].ToString());
                                            }
                                            if (archToken["meshsize"] != null)
                                            {
                                                smn.MeshSize = double.Parse(archToken["meshsize"].ToString());
                                            }
                                            archProvider.Update(smn);
                                            jinstrument = Jsonifier.ToJson(instrument, smn);
                                            break;

                                        case "StandardPlanktonNet":
                                            StandardPlanktonNet spn = archProvider.AddStandardPlanktonNet(instrument.Identity);
                                            if (archToken["openarea"] != null)
                                            {
                                                spn.OpenArea = double.Parse(archToken["openarea"].ToString());
                                            }
                                            if (archToken["meshsize"] != null)
                                            {
                                                spn.MeshSize = double.Parse(archToken["meshsize"].ToString());
                                            }
                                            if (archToken["codsize"] != null)
                                            {
                                                spn.MeshSize = double.Parse(archToken["codsize"].ToString());
                                            }
                                            archProvider.Update(spn);
                                            jinstrument = Jsonifier.ToJson(instrument, spn);
                                            break;

                                        case "WingedBagNet":
                                            WingedBagNet wbn = archProvider.AddWingedBagNet(instrument.Identity);
                                            if (archToken["length"] != null)
                                            {
                                                wbn.Length = double.Parse(archToken["length"].ToString());
                                            }
                                            if (archToken["depth"] != null)
                                            {
                                                wbn.Depth = double.Parse(archToken["depth"].ToString());
                                            }
                                            if (archToken["meshsizewings"] != null)
                                            {
                                                wbn.Length = double.Parse(archToken["meshsizewings"].ToString());
                                            }
                                            if (archToken["meshsizebag"] != null)
                                            {
                                                wbn.Depth = double.Parse(archToken["meshsizebag"].ToString());
                                            }
                                            archProvider.Update(wbn);
                                            jinstrument = Jsonifier.ToJson(instrument, wbn);
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        jinstrument = Jsonifier.ToJson(instrument);
                                    }

                                    if (jinstrument != null)
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jinstrument.ToString()));
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                                    }
                                    return;
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("update", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        //provider and token
                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        InstrumentProviderBase provider = InstrumentManager.Instance.GetInstrumentProvider(user);
                        InstrumentKnownArchetypeProviderBase archProvider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                        if (provider != null && token != null)
                        {
                            //GUID must be provided
                            CompoundIdentity cid = JsonUtils.ToId(token["id"]);  //instrument ID

                            //fetch stored object
                            bool       dirty      = false;
                            bool       result     = true;
                            Instrument instrument = provider.Get(cid);
                            if (instrument != null)
                            {
                                //update archetype instance if necessary
                                //assumes inbound archtype is self-consistent and consistent with instrument type (validation should occur in provider and by requester)
                                if (token.SelectToken("archid") != null)
                                {
                                    //clear previous
                                    archProvider.Delete(instrument.Identity);

                                    //add new, if defined
                                    if (JsonUtils.ToId(token["archid"]) != null)
                                    {
                                        CompoundIdentity arch_id         = JsonUtils.ToId(token["archid"]);
                                        JToken           archToken       = token["archdata"];
                                        string           archetypeString = archProvider.GetArchetypeType(arch_id);
                                        switch (archetypeString)
                                        {
                                        case "SimpleTrapDredge":
                                            SimpleTrapDredge std = archProvider.AddSimpleTrapDredge(instrument.Identity);
                                            if (archToken["openarea"] != null)
                                            {
                                                std.OpenArea = double.Parse(archToken["openarea"].ToString());
                                            }
                                            result &= archProvider.Update(std);
                                            break;

                                        case "StandardMeshNet":
                                            StandardMeshNet smn = archProvider.AddStandardMeshNet(instrument.Identity);
                                            if (archToken["length"] != null)
                                            {
                                                smn.Length = double.Parse(archToken["length"].ToString());
                                            }
                                            if (archToken["depth"] != null)
                                            {
                                                smn.Depth = double.Parse(archToken["depth"].ToString());
                                            }
                                            if (archToken["meshsize"] != null)
                                            {
                                                smn.MeshSize = double.Parse(archToken["meshsize"].ToString());
                                            }
                                            result &= archProvider.Update(smn);
                                            break;

                                        case "StandardPlanktonNet":
                                            StandardPlanktonNet spn = archProvider.AddStandardPlanktonNet(instrument.Identity);
                                            if (archToken["openarea"] != null)
                                            {
                                                spn.OpenArea = double.Parse(archToken["openarea"].ToString());
                                            }
                                            if (archToken["meshsize"] != null)
                                            {
                                                spn.MeshSize = double.Parse(archToken["meshsize"].ToString());
                                            }
                                            if (archToken["codsize"] != null)
                                            {
                                                spn.CodSize = double.Parse(archToken["codsize"].ToString());
                                            }
                                            result &= archProvider.Update(spn);
                                            break;

                                        case "WingedBagNet":
                                            WingedBagNet wbn = archProvider.AddWingedBagNet(instrument.Identity);
                                            if (archToken["length"] != null)
                                            {
                                                wbn.Length = double.Parse(archToken["length"].ToString());
                                            }
                                            if (archToken["depth"] != null)
                                            {
                                                wbn.Depth = double.Parse(archToken["depth"].ToString());
                                            }
                                            if (archToken["meshsizewings"] != null)
                                            {
                                                wbn.MeshSizeWings = double.Parse(archToken["meshsizewings"].ToString());
                                            }
                                            if (archToken["meshsizebag"] != null)
                                            {
                                                wbn.MeshSizeBag = double.Parse(archToken["meshsizebag"].ToString());
                                            }
                                            result &= archProvider.Update(wbn);
                                            break;
                                        }
                                    }
                                }

                                if (result)
                                {
                                    //continue to check instrument
                                    //## REQUIRED ##
                                    //name
                                    if (token.SelectToken("name") != null)
                                    {
                                        string name = token["name"].ToString();
                                        if (!string.IsNullOrEmpty(name))
                                        {
                                            instrument.Name = name;
                                            dirty           = true;
                                        }
                                        else
                                        {
                                            RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable
                                            return;
                                        }
                                    }

                                    //owning org
                                    if (token.SelectToken("orgid") != null)
                                    {
                                        CompoundIdentity org_cid = JsonUtils.ToId(token["orgid"]);
                                        if (org_cid != null)
                                        {
                                            instrument.OwningOrganizationIdentity = org_cid;
                                            dirty = true;
                                        }
                                        else
                                        {
                                            RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable
                                            return;
                                        }
                                    }

                                    //type
                                    if (token.SelectToken("typeid") != null)

                                    {
                                        CompoundIdentity type = JsonUtils.ToId(token["typeid"]);
                                        if (type != null)
                                        {
                                            instrument.InstrumentTypeIdentity = type;
                                            dirty = true;
                                        }
                                        else
                                        {
                                            RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //intrument type is required and not nullable
                                            return;
                                        }
                                    }

                                    //## OPTIONALS ##

                                    //description
                                    if (token.SelectToken("desc") != null)
                                    {
                                        string desc = (token["desc"] != null) ? token["desc"].ToString() : null;
                                        instrument.Description = desc;
                                        dirty = true;
                                    }

                                    //serial number
                                    if (token.SelectToken("serial") != null)
                                    {
                                        string serial = token["serial"] != null ? token["serial"].ToString() : null;
                                        instrument.SerialNumber = serial;
                                        dirty = true;
                                    }

                                    //manufacturer
                                    if (token.SelectToken("manf") != null)

                                    {
                                        CompoundIdentity manf = JsonUtils.ToId(token["manf"]);
                                        instrument.ManufacturerId = manf;
                                        dirty = true;
                                    }

                                    //update instrument if necessary
                                    if (dirty)
                                    {
                                        //update
                                        result &= provider.Update(instrument);
                                        if (result == true)
                                        {
                                            RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        //return ok - no values were modified
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                        return;
                                    }
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));  //default
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken t = JsonUtils.GetDataPayload(context.Request);
                        HashSet <CompoundIdentity>           cids         = JsonUtils.ToIds(t);
                        InstrumentProviderBase               provider     = InstrumentManager.Instance.GetInstrumentProvider(user);
                        InstrumentKnownArchetypeProviderBase archProvider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                        if (provider != null && cids != null)
                        {
                            bool result = true;
                            foreach (CompoundIdentity cid in cids)
                            {
                                result &= provider.Delete(cid);
                            }

                            if (result == true)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                            }
                            else
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                            }
                            return;
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
            }

            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }
Exemple #17
0
        public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel)
        {
            if (context.Request.Method == "POST") //all we support is get/post
            {
                if (method.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    Get(user, context, cancel);
                    return;
                }
                else if (method.Equals("in", StringComparison.OrdinalIgnoreCase))
                {
                    try{
                        HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request));
                        if (ids != null)
                        {
                            GetIds(ids, user, context, cancel);
                            return;
                        }
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                }
                else if (method.Equals("find", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        if (token != null)
                        {
                            if (token["name"] != null)
                            {
                                string name = token["name"].ToString();
                                GetName(name, user, context, cancel);
                                return;
                            }
                            else if (token["orgid"] != null)
                            {
                                CompoundIdentity owner_id = JsonUtils.ToId(token["orgid"]);
                                GetByOwner(owner_id, user, context, cancel);
                                return;
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("children", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        ProjectProviderBase provider = ProjectManager.Instance.GetProvider(user);
                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        if (token != null && provider != null)
                        {
                            if (token["parentid"] != null)
                            {
                                CompoundIdentity parent_id = JsonUtils.ToId(token["parentid"]);
                                Project          parent    = provider.Get(parent_id);
                                if (parent != null)
                                {
                                    IEnumerable <Project> projects = provider.GetFor(parent);
                                    JArray jprojects = Jsonifier.ToJson(projects);
                                    if (jprojects != null)
                                    {
                                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jprojects);
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                                    }
                                    return;
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("create", StringComparison.OrdinalIgnoreCase))
                {
                    string                     name;
                    string                     desc           = null;
                    JToken                     token          = null;
                    Project                    project        = null;
                    Project                    parent_project = null;
                    CompoundIdentity           org_cid        = null;
                    CompoundIdentity           proj_cid       = null;
                    HashSet <CompoundIdentity> affiliate_cids = null;
                    ProjectProviderBase        provider       = null;

                    try
                    {
                        //token and provider
                        token    = JsonUtils.GetDataPayload(context.Request);
                        provider = ProjectManager.Instance.GetProvider(user);
                        if (provider != null && token != null)
                        {
                            //required inputs
                            org_cid = JsonUtils.ToId(token["orgid"]);
                            name    = token["name"].ToString();
                            if (org_cid != null && !string.IsNullOrEmpty(name))
                            {
                                desc = token["desc"] != null ? token["desc"].ToString() : null;

                                if (token["affiliateorgid"] != null)
                                {
                                    affiliate_cids = JsonUtils.ToIds(token["affiliateorgid"]);  //could be multiple
                                }
                                if (token["parentid"] != null)
                                {
                                    proj_cid       = JsonUtils.ToId(token["parentid"]);
                                    parent_project = (proj_cid != null) ? provider.Get(proj_cid) : null;
                                }

                                //create; optionally update affiliations
                                project = provider.Create(name, org_cid, parent_project, desc);
                                if (project != null)
                                {
                                    bool result = true;
                                    //update with affiliates if necessary
                                    if (affiliate_cids != null)
                                    {
                                        foreach (CompoundIdentity cid in affiliate_cids)
                                        {
                                            project.Affiliates.Add(cid);
                                        }
                                        result &= provider.Update(project);
                                    }

                                    if (result == true)
                                    {
                                        JObject jproject = Jsonifier.ToJson(project);
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jproject.ToString()));
                                        return;
                                    }
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken t = JsonUtils.GetDataPayload(context.Request);
                        HashSet <CompoundIdentity> cids     = JsonUtils.ToIds(t);
                        ProjectProviderBase        provider = ProjectManager.Instance.GetProvider(user);
                        if (provider != null && cids != null)
                        {
                            bool result = true;
                            foreach (CompoundIdentity cid in cids)
                            {
                                result &= provider.Delete(cid);
                            }

                            if (result == true)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                            }
                            else
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                            }
                            return;
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("update", StringComparison.OrdinalIgnoreCase))
                {
                    string                     name;
                    string                     desc           = null;
                    JToken                     token          = null;
                    Project                    project        = null;
                    CompoundIdentity           cid            = null;
                    CompoundIdentity           org_cid        = null;
                    CompoundIdentity           parent_cid     = null;
                    HashSet <CompoundIdentity> affiliate_cids = null;
                    ProjectProviderBase        provider       = null;

                    try
                    {
                        token    = JsonUtils.GetDataPayload(context.Request);
                        provider = ProjectManager.Instance.GetProvider(user);
                        if (provider != null && token != null)
                        {
                            //GUID must be provided
                            cid = JsonUtils.ToId(token["id"]);

                            //fetch stored object
                            bool dirty = false;
                            project = provider.Get(cid);
                            if (project != null)
                            {
                                //## REQUIRED ##

                                //name
                                if (token.SelectToken("name") != null)
                                {
                                    name = token["name"].ToString();
                                    if (!string.IsNullOrEmpty(name))
                                    {
                                        project.Name = name;
                                        dirty        = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable
                                        return;
                                    }
                                }

                                //owning org
                                if (token.SelectToken("orgid") != null)
                                {
                                    org_cid = JsonUtils.ToId(token["orgid"]);
                                    if (org_cid != null)
                                    {
                                        project.PrincipalOrganization = org_cid;
                                        dirty = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable
                                        return;
                                    }
                                }

                                //## OPTIONALS ##

                                //description
                                if (token.SelectToken("desc") != null)
                                {
                                    desc = (token["desc"] != null) ? token["desc"].ToString() : null;
                                    project.Description = desc;
                                    dirty = true;
                                }

                                //parent project
                                if (token.SelectToken("parentid") != null)
                                {
                                    parent_cid       = JsonUtils.ToId(token["parentid"]);
                                    project.ParentId = parent_cid;  //could be null
                                    dirty            = true;
                                }

                                //affiliate orgs
                                if (token.SelectToken("affiliateorgid") != null)
                                {
                                    affiliate_cids = JsonUtils.ToIds(token["affiliateorgid"]);
                                    //reset affiliates
                                    List <CompoundIdentity> clist = new List <CompoundIdentity>();
                                    foreach (CompoundIdentity c in project.Affiliates)
                                    {
                                        clist.Add(c);
                                    }
                                    foreach (CompoundIdentity c in clist)
                                    {
                                        project.Affiliates.Remove(c);
                                    }
                                    if (affiliate_cids != null)
                                    {
                                        foreach (CompoundIdentity c in affiliate_cids)
                                        {
                                            project.Affiliates.Add(c);
                                        }
                                    }
                                    dirty = true;
                                }

                                if (dirty)
                                {
                                    //update
                                    bool result = provider.Update(project);
                                    if (result == true)
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                        return;
                                    }
                                }
                                else
                                {
                                    //return ok - no values were modified
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                    return;
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
            }
            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }
Exemple #18
0
 public WorkItems(CoreDbContext context, UserSecurityContext userSecurityContext)
 {
     this.context             = context;
     this.userSecurityContext = userSecurityContext;
 }
 protected TaxaUnitProviderBase(UserSecurityContext context)
 {
     this.Context = context;
 }
Exemple #20
0
 public override IVegSampleProvider GetSampleProvider(UserSecurityContext context)
 {
     return(new PgVegSampleProvider(context));
 }
Exemple #21
0
 public override IWQDeploymentProvider GetDeploymentProvider(UserSecurityContext context)
 {
     return(new PgWQDeploymentProvider(context));
 }
Exemple #22
0
        public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel)
        {
            if (context.Request.Method == "POST")
            {
                if (method.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    Get(user, context, cancel);
                    return;
                }
                else if (method.Equals("find", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        if (token != null)
                        {
                            if (token["name"] != null)
                            {
                                string name = token["name"].ToString();
                                GetName(name, user, context, cancel);
                                return;
                            }
                            else if (token["orgid"] != null)
                            {
                                CompoundIdentity org_id = JsonUtils.ToId(token["orgid"]);
                                GetByOrg(org_id, user, context, cancel);
                                return;
                            }
                            else if (token["activityid"] != null)
                            {
                                CompoundIdentity activity_id = JsonUtils.ToId(token["activityid"]);
                                GetByActivity(activity_id, user, context, cancel);
                                return;
                            }
                        }


                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("in", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request));
                        if (ids != null)
                        {
                            GetIds(ids, user, context, cancel);
                            return;
                        }
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                }
                else if (method.Equals("create", StringComparison.OrdinalIgnoreCase))
                {
                    JToken token = null;
                    FieldTripProviderBase provider = null;
                    FieldTrip             trip     = null;
                    FieldActivity         activity = null;
                    CompoundIdentity      org_id   = null;
                    CompoundIdentity      act_id   = null;
                    string name;
                    string desc = null;

                    try
                    {
                        //token and provider
                        token    = JsonUtils.GetDataPayload(context.Request);
                        provider = FieldActivityManager.Instance.GetFieldTripProvider(user);
                        if (provider != null && token != null)
                        {
                            //required inputs
                            name     = token["name"].ToString();
                            org_id   = JsonUtils.ToId(token["orgid"]);
                            act_id   = JsonUtils.ToId(token["activityid"]);
                            activity = FieldActivityManager.Instance.GetFieldActivityProvider(user).Get(act_id);
                            if (org_id != null && activity != null && !string.IsNullOrEmpty(name))
                            {
                                desc = token["desc"] != null ? token["desc"].ToString() : null;

                                //start and end dates
                                //ValueRange<DateTime> range = JsonUtils.ToRange(token, "start", "end");

                                //create
                                trip = provider.Create(name, activity, org_id, desc);
                                if (trip != null)
                                {
                                    JObject jtrip = Jsonifier.ToJson(trip);
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jtrip.ToString()));
                                    return;
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("update", StringComparison.OrdinalIgnoreCase))
                {
                    JToken token = null;
                    FieldTripProviderBase provider = null;
                    FieldTrip             trip     = null;
                    CompoundIdentity      cid      = null;
                    CompoundIdentity      org_id   = null;
                    CompoundIdentity      act_id   = null;
                    string name;
                    string desc = null;

                    try
                    {
                        //token and provider
                        token    = JsonUtils.GetDataPayload(context.Request);
                        provider = FieldActivityManager.Instance.GetFieldTripProvider(user);
                        if (provider != null && token != null)
                        {
                            //GUID must be provided
                            cid = JsonUtils.ToId(token["id"]);

                            //fetch stored object
                            bool dirty = false;
                            trip = provider.Get(cid);
                            if (trip != null)
                            {
                                //## REQUIRED ##

                                //name
                                if (token.SelectToken("name") != null)
                                {
                                    name = token["name"].ToString();
                                    if (!string.IsNullOrEmpty(name))
                                    {
                                        trip.Name = name;
                                        dirty     = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable
                                        return;
                                    }
                                }

                                //owning org
                                if (token.SelectToken("orgid") != null)
                                {
                                    org_id = JsonUtils.ToId(token["orgid"]);
                                    if (org_id != null)
                                    {
                                        trip.PrincipalOrgId = org_id;
                                        dirty = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable
                                        return;
                                    }
                                }

                                //field activity
                                if (token.SelectToken("activityid") != null)
                                {
                                    act_id = JsonUtils.ToId(token["activityid"]);
                                    if (act_id != null)
                                    {
                                        trip.FieldActivityId = act_id;
                                        dirty = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //project is required and not nullable
                                        return;
                                    }
                                }

                                //## OPTIONALS ##

                                //description
                                if (token.SelectToken("desc") != null)
                                {
                                    desc             = (token["desc"] != null) ? token["desc"].ToString() : null;
                                    trip.Description = desc;
                                    dirty            = true;
                                }

                                //start and end dates
                                //if (token.SelectToken("start") != null)
                                //{
                                //}

                                if (dirty)
                                {
                                    //update
                                    bool result = provider.Update(trip);
                                    if (result == true)
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                        return;
                                    }
                                }
                                else
                                {
                                    //return ok - no values were modified
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                    return;
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken t = JsonUtils.GetDataPayload(context.Request);
                        HashSet <CompoundIdentity> cids     = JsonUtils.ToIds(t);
                        FieldTripProviderBase      provider = FieldActivityManager.Instance.GetFieldTripProvider(user);
                        if (cids != null && provider != null)
                        {
                            bool result = true;
                            foreach (CompoundIdentity cid in cids)
                            {
                                result &= provider.Delete(cid);
                            }

                            if (result == true)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                return;
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
            }
            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }
Exemple #23
0
 public override IWQMeasurementProvider GetMeasurementProvider(UserSecurityContext context)
 {
     return(new PgWQMeasurementProvider(context));
 }
        public void RejectAccessRequest(Guid accessRequestId, UserSecurityContext context)
        {
            AccessRequest request = _accessRequestRepo.GetOne(accessRequestId);

            ApproveAccessRequest(request, context, ApprovalDecisionType.Reject);
        }
Exemple #25
0
 protected override IAuthenticationProvider GetProvider(UserSecurityContext context)
 {
     return(new UserPasswordAuthenticationProvider(context, this.GetCredentialProvider(context), this.HistoryProvider.GetProvider()));
 }
        public OrganizationMember RevokeAdminPermisson(Guid organizationId, Guid personId, UserSecurityContext context)
        {
            var orgMember = _organzationMemberRepo.Find(null, p => p.OrganizationId == organizationId && p.PersonId == personId && p.IsAdministrator.GetValueOrDefault(false)).Items?.FirstOrDefault();

            if (orgMember != null)
            {
                //check if you are admin to revoke the admin rights of other users
                bool IsOrgAdmin = Array.Exists(context.OrganizationId, o => o.CompareTo(organizationId) == 0);
                if (IsOrgAdmin && context.PersonId == personId)
                {
                    return(orgMember);
                }

                if (IsOrgAdmin)
                {
                    orgMember.IsAdministrator = false;
                    orgMember = _organzationMemberRepo.Update(orgMember);
                }
            }
            return(orgMember);
        }
Exemple #27
0
 public FishDetProcessor(UserSecurityContext ctx) : base(ctx)
 {
 }
		protected TaxaCommonNameProviderBase(UserSecurityContext context)
		{
			this.Context = context;
		}
Exemple #29
0
 public DayReport(CoreDbContext dbContext, UserSecurityContext userSecurityContext)
 {
     this.dbContext           = dbContext;
     this.userSecurityContext = userSecurityContext;
 }
Exemple #30
0
 protected InstrumentProviderBase(UserSecurityContext context)
 {
     this.Context = context;
 }
 internal PgOrgHierarchy(UserSecurityContext context, CompoundIdentity identity, CompoundIdentity owningOrgId, string name, string description) : base(context, identity, owningOrgId, name, description)
 {
 }