コード例 #1
0
        public ClientModel Post([FromUri] string option, [FromBody] ClientModel model, int id)
        {
            ClientModel result = null;

            switch (option)
            {
            case "current":
                ClientOrg co = DataSession.Single <ClientOrg>(id);
                ClientOrg mo = DataSession.Single <ClientOrg>(model.ClientOrgID);

                if (co != null && mo != null)
                {
                    var cm = DataSession.Query <ClientManager>().FirstOrDefault(x => x.ClientOrg == co && x.ManagerOrg == mo);

                    if (cm == null)
                    {
                        //no existing ClientManager record so create a new one
                        cm = new ClientManager()
                        {
                            ClientOrg  = co,
                            ManagerOrg = mo
                        };

                        DataSession.Insert(cm);
                    }

                    Provider.Data.ActiveLog.Enable(cm);

                    result = ApiUtility.CreateClientModel(cm.ManagerOrg.CreateModel <IClient>());
                }
                break;
            }

            return(result);
        }
コード例 #2
0
ファイル: ApiUtility.cs プロジェクト: lurienanofab/data
        public static AccountModel[] GetCurrentAccounts(ClientModel model)
        {
            ClientOrg             co    = DataSession.Single <ClientOrg>(model.ClientOrgID);
            IList <ClientAccount> query = DataSession.Query <ClientAccount>().Where(x => x.ClientOrg == co && x.Active).ToList();

            return(query.Select(x => x.Account).Select(x => CreateAccountModel(x)).OrderBy(x => x.AccountName).ToArray());
        }
コード例 #3
0
ファイル: ApiUtility.cs プロジェクト: lurienanofab/data
        public static ClientModel[] GetCurrentManagers(ClientModel model)
        {
            ClientOrg co      = DataSession.Single <ClientOrg>(model.ClientOrgID);
            var       query   = DataSession.Query <ClientManager>().Where(x => x.ClientOrg == co && x.Active).Select(x => x.ManagerOrg);
            var       current = query.CreateModels();

            return(current.Select(CreateClientModel).OrderBy(x => x.DisplayName).ToArray());
        }
コード例 #4
0
ファイル: ApiUtility.cs プロジェクト: lurienanofab/data
        public static ClientModel[] GetAvailableManagers(ClientModel model)
        {
            ClientOrg co = DataSession.Single <ClientOrg>(model.ClientOrgID);

            ClientOrg[]           current = DataSession.Query <ClientManager>().Where(x => x.ClientOrg == co && x.Active).Select(x => x.ManagerOrg).ToArray();
            IEnumerable <IClient> all     = Provider.Data.Client.SelectOrgManagers(co.Org.OrgID);

            ClientModel[] result = all.Where(a => !current.Select(c => c.ClientOrgID).Contains(a.ClientOrgID)).Select(x => CreateClientModel(x)).OrderBy(x => x.DisplayName).ToArray();
            return(result);
        }
コード例 #5
0
        public override void Load()
        {
            Message = string.Empty;

            if (ClientID == 0)
            {
                Active = true;
                return;
            }

            Org org = DataSession.Single <Org>(OrgID);

            if (org == null)
            {
                Message = GetAlert("Cannot find OrgID {0}", OrgID);
            }
            else
            {
                Client c = DataSession.Single <Client>(ClientID);
                if (c == null)
                {
                    Active = true;
                    return;
                }
                else
                {
                    UserName         = c.UserName;
                    LName            = c.LName;
                    FName            = c.FName;
                    MName            = c.MName;
                    PrivFlag         = Convert.ToInt32(c.Privs);
                    Communities      = c.Communities;
                    TechnicalFieldID = c.TechnicalInterestID;
                    Active           = c.Active;

                    ClientOrg co = DataSession.Query <ClientOrg>().FirstOrDefault(x => x.Client.ClientID == ClientID && x.Org.OrgID == OrgID);
                    if (co != null)
                    {
                        ClientOrgID         = co.ClientOrgID;
                        DepartmentID        = co.Department.DepartmentID;
                        RoleID              = co.Role.RoleID;
                        Phone               = co.Phone;
                        Email               = co.Email;
                        IsManager           = co.IsManager;
                        IsFinManager        = co.IsFinManager;
                        SubsidyStartDate    = co.SubsidyStartDate;
                        NewFacultyStartDate = co.NewFacultyStartDate;
                    }
                }
            }
        }
コード例 #6
0
        public bool Delete([FromUri] string option, [FromBody] ClientModel model, int id = 0)
        {
            bool result = false;

            switch (option)
            {
            case "current":
                ClientOrg co = DataSession.Single <ClientOrg>(id);
                ClientOrg mo = DataSession.Single <ClientOrg>(model.ClientOrgID);
                var       cm = DataSession.Query <ClientManager>().FirstOrDefault(x => x.ClientOrg == co && x.ManagerOrg == mo && x.Active);
                if (cm != null)
                {
                    Provider.Data.ActiveLog.Disable(cm);

                    //remove account access if no other manager manages the acct
                    ClientModel    m = ApiUtility.CreateClientModel(co.CreateModel <IClient>());
                    AccountModel[] currentAccounts = ApiUtility.GetCurrentAccounts(m);
                    ClientModel[]  currentManagers = ApiUtility.GetCurrentManagers(m);

                    foreach (AccountModel acct in currentAccounts)
                    {
                        bool hasManagerForAccount = false;
                        foreach (ClientModel mgr in ApiUtility.GetCurrentManagers(acct))
                        {
                            if (currentManagers.Select(x => x.ClientOrgID).Contains(mgr.ClientOrgID))
                            {
                                hasManagerForAccount = true;
                                break;
                            }
                        }

                        if (!hasManagerForAccount)
                        {
                            //the client is assigned to an acct but does not have a manager who manages the acct
                            ClientAccount ca = DataSession.Query <ClientAccount>().FirstOrDefault(x => x.ClientOrg.ClientOrgID == m.ClientOrgID && x.Account.AccountID == acct.AccountID);

                            if (!ca.Manager)     //do not deactivate if this client is also the acct manager!
                            {
                                Provider.Data.ActiveLog.Disable(ca);
                            }
                        }
                    }

                    result = true;
                }
                break;
            }

            return(result);
        }
コード例 #7
0
ファイル: ApiUtility.cs プロジェクト: lurienanofab/data
        public static AddressModel[] GetCurrentAddresses(string type, int id)
        {
            switch (type)
            {
            case "client":
                ClientOrg co = DataSession.Single <ClientOrg>(id);
                if (co != null)
                {
                    IList <Address> query = DataSession.Query <Address>().Where(x => x.AddressID == co.ClientAddressID).ToList();
                    return(query.Select(x => CreateAddressModel(type, x)).OrderBy(x => x.State).ThenBy(x => x.StreetAddress1).ToArray());
                }
                break;
            }

            return(new AddressModel[] { });
        }
コード例 #8
0
        public int MinimumDaysForApportionment(ClientOrg co, Room r, DateTime period)
        {
            var query = Session.Query <ToolData>().Where(x => x.ClientID == co.Client.ClientID && x.Period == period).Where(x => Session.Get <Account>(x.AccountID).Org == co.Org);

            var join = query.Join(Session.Query <Reservation>(), o => o.ReservationID, i => i.ReservationID, (o, i) => new { ToolData = o, Reservation = i });

            var days = join
                       .Where(x => x.Reservation.Resource.ProcessTech.Lab.Room == r && x.Reservation.IsStarted)
                       .Select(x => x.ToolData.ActDate).ToList();

            var distinctDays = days.Select(x => x.Day).Distinct();

            var result = distinctDays.Count();

            return(result);
        }
コード例 #9
0
        public bool Delete([FromBody] AddressModel model, int id)
        {
            Address addr = DataSession.Single <Address>(model.AddressID);

            ClientOrg co = DataSession.Single <ClientOrg>(id);

            if (addr != null && co != null)
            {
                DataSession.Delete(addr);
                co.ClientAddressID = 0;
                DataSession.SaveOrUpdate(co);

                return(true);
            }

            return(false);
        }
コード例 #10
0
        public AddressModel Post([FromBody] AddressModel model, int id = 0)
        {
            Address      addr   = DataSession.Single <Address>(model.AddressID);
            AddressModel result = null;

            if (addr != null)
            {
                addr.City            = model.City;
                addr.Country         = model.Country;
                addr.InternalAddress = model.Attention;
                addr.State           = model.State;
                addr.StrAddress1     = model.StreetAddress1;
                addr.StrAddress2     = model.StreetAddress2;
                addr.Zip             = model.Zip;
                DataSession.SaveOrUpdate(addr);
                result = ApiUtility.CreateAddressModel("client", addr);
            }
            else
            {
                //add a new address to this ClientOrg
                ClientOrg co = DataSession.Single <ClientOrg>(id);
                if (co != null)
                {
                    addr = new Address()
                    {
                        City            = model.City,
                        Country         = model.Country,
                        InternalAddress = model.Attention,
                        State           = model.State,
                        StrAddress1     = model.StreetAddress1,
                        StrAddress2     = model.StreetAddress2,
                        Zip             = model.Zip
                    };

                    DataSession.SaveOrUpdate(addr);

                    co.ClientAddressID = addr.AddressID;

                    DataSession.SaveOrUpdate(co);

                    result = ApiUtility.CreateAddressModel("client", addr);
                }
            }

            return(result);
        }
コード例 #11
0
ファイル: OrgRepository.cs プロジェクト: lurienanofab/lnf
        public IEnumerable <IOrg> GetActiveOrgs(int clientId, DateTime sd, DateTime ed)
        {
            ActiveLog alog = null;
            ClientOrg co   = null;
            Org       org  = null;

            var query = Session.QueryOver(() => org)
                        .JoinAlias(() => org, () => co.Org)
                        .JoinAlias(() => alog.Record, () => org.OrgID)
                        .Where(() => alog.TableName == "ClientOrg" && alog.EnableDate < ed && (alog.DisableDate == null || alog.DisableDate > sd))
                        .And(() => co.Client.ClientID == clientId);

            var list = query.List();

            var result = list.CreateModels <IOrg>();

            return(result);
        }