예제 #1
0
        public bool Delete(int orgId, int addressId, string addressType)
        {
            var entity = DataSession.Single <Address>(addressId);

            if (entity != null)
            {
                DataSession.Delete(new[] { entity });
                OrgAddressType type = (OrgAddressType)Enum.Parse(typeof(OrgAddressType), addressType);
                Org            org  = DataSession.Single <Org>(orgId);
                switch (type)
                {
                case OrgAddressType.Billing:
                    org.DefBillAddressID = 0;
                    break;

                case OrgAddressType.Client:
                    org.DefClientAddressID = 0;
                    break;

                case OrgAddressType.Shipping:
                    org.DefShipAddressID = 0;
                    break;
                }

                DataSession.SaveOrUpdate(org);

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        public void RequestApproval(int poid)
        {
            var po = Require <Ordering.PurchaseOrder>(x => x.POID, poid);

            po.Status = GetStatus(OrderStatus.AwaitingApproval);

            DataSession.SaveOrUpdate(po);

            Tracking.Track(TrackingCheckpoints.SentForApproval, po.CreateModel <IPurchaseOrder>(), Context.CurrentUser.ClientID);
        }
예제 #3
0
        public void Reject(int poid, int approverId)
        {
            var po = Require <Ordering.PurchaseOrder>(x => x.POID, poid);

            po.Status = GetStatus(OrderStatus.Draft);

            DataSession.SaveOrUpdate(po);

            Tracking.Track(TrackingCheckpoints.Rejected, po.CreateModel <IPurchaseOrder>(), approverId);
        }
예제 #4
0
        public AddressModel Post([FromBody] AddressModel model, int orgId)
        {
            Address entity;

            if (model.AddressID > 0)
            {
                //update existing
                entity = DataSession.Single <Address>(model.AddressID);
                entity.InternalAddress = model.Attention;
                entity.StrAddress1     = model.StreetAddress1;
                entity.StrAddress2     = model.StreetAddress2;
                entity.City            = model.City;
                entity.State           = model.State;
                entity.Zip             = model.Zip;
                entity.Country         = model.Country;
            }
            else
            {
                //add new
                entity = new Address()
                {
                    InternalAddress = model.Attention,
                    StrAddress1     = model.StreetAddress1,
                    StrAddress2     = model.StreetAddress2,
                    City            = model.City,
                    State           = model.State,
                    Zip             = model.Zip,
                    Country         = model.Country
                };
            }

            DataSession.SaveOrUpdate(entity);

            OrgAddressType type = (OrgAddressType)Enum.Parse(typeof(OrgAddressType), model.AddressType);
            Org            org  = DataSession.Single <Org>(orgId);

            switch (type)
            {
            case OrgAddressType.Client:
                org.DefClientAddressID = entity.AddressID;
                break;

            case OrgAddressType.Billing:
                org.DefBillAddressID = entity.AddressID;
                break;

            case OrgAddressType.Shipping:
                org.DefShipAddressID = entity.AddressID;
                break;
            }

            DataSession.SaveOrUpdate(org);

            return(GetModel(type, entity));
        }
예제 #5
0
        public void Approve(int poid, int approverId)
        {
            var po = Require <Ordering.PurchaseOrder>(x => x.POID, poid);

            po.Status         = GetStatus(OrderStatus.Approved);
            po.RealApproverID = approverId;
            po.ApprovalDate   = DateTime.Now;

            DataSession.SaveOrUpdate(po);

            Tracking.Track(TrackingCheckpoints.Approved, po.CreateModel <IPurchaseOrder>(), approverId);
        }
예제 #6
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);
        }
예제 #7
0
        public ActiveLogModel Post([FromBody] ActiveLogModel model)
        {
            ActiveLog alog = DataSession.Single <ActiveLog>(model.LogID);

            if (alog == null)
            {
                return(null);
            }

            alog.EnableDate = model.EnableDate;
            DataSession.SaveOrUpdate(alog);

            return(new ActiveLogModel()
            {
                LogID = alog.LogID, EnableDate = alog.EnableDate
            });
        }
예제 #8
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);
        }
예제 #9
0
        protected void Extend_Command(object sender, CommandEventArgs e)
        {
            var clientId  = Convert.ToInt32(e.CommandArgument);
            var authLevel = (ClientAuthLevel)Enum.Parse(typeof(ClientAuthLevel), e.CommandName);
            var cc        = CurrentClients.FirstOrDefault(x => x.ClientID == clientId);

            if (cc != null)
            {
                var rc = DataSession.Single <ResourceClient>(cc.ResourceClientID);
                rc.Expiration = DateTime.Now.AddMonths(GetCurrentResource().AuthDuration);
                DataSession.SaveOrUpdate(rc);
                ClearResourceClientsCache();
            }

            Fill(authLevel);
            FillClients();
        }
예제 #10
0
        public bool SaveRoom()
        {
            if (string.IsNullOrEmpty(RoomName))
            {
                Message = string.Format("<div class=\"alert alert-danger\" role=\"alert\">Room name must not be blank</div>", RoomID);
                return(false);
            }

            Room room;

            if (RoomID == 0)
            {
                room = new Room();
            }
            else
            {
                room = DataSession.Single <Room>(RoomID);
                if (room == null)
                {
                    Message = string.Format("<div class=\"alert alert-danger\" role=\"alert\">Cannot find RoomID {0}</div>", RoomID);
                    return(false);
                }
            }

            int?parentId = null;

            if (ParentID > 0)
            {
                parentId = ParentID;
            }

            room.ParentID          = parentId;
            room.RoomName          = RoomName;
            room.DisplayName       = string.IsNullOrEmpty(DisplayName) ? null : DisplayName;
            room.PassbackRoom      = PassbackRoom;
            room.Billable          = Billable;
            room.ApportionDailyFee = ApportionDailyFee;
            room.ApportionEntryFee = ApportionEntryFee;
            room.Active            = Active;

            DataSession.SaveOrUpdate(room);

            return(true);
        }
예제 #11
0
 public DepartmentModel[] Post([FromBody] DepartmentModel model)
 {
     if (model.DepartmentID > 0)
     {
         //update existing
         var entity = DataSession.Single <Department>(model.DepartmentID);
         entity.DepartmentName = model.DepartmentName;
         DataSession.SaveOrUpdate(entity);
         return(new DepartmentModel[] { GetModel(entity) });
     }
     else
     {
         //add new
         var entity = new Department()
         {
             DepartmentName = model.DepartmentName,
             Org            = DataSession.Single <Org>(model.OrgID)
         };
         DataSession.SaveOrUpdate(entity);
         return(Get(model.OrgID));
     }
 }
예제 #12
0
        public OrgDepartmentModel Post([FromBody] OrgDepartmentModel model, int orgId)
        {
            Department entity;

            if (model.DepartmentID > 0)
            {
                //update existing
                entity = DataSession.Single <Department>(model.DepartmentID);
                entity.DepartmentName = model.DepartmentName;
            }
            else
            {
                //add new
                entity = new Department()
                {
                    DepartmentName = model.DepartmentName,
                    Org            = DataSession.Single <Org>(orgId)
                };
            }

            DataSession.SaveOrUpdate(entity);
            return(GetModel(entity));
        }
예제 #13
0
        public override bool Save()
        {
            int errors = 0;

            Message = string.Empty;

            if (string.IsNullOrEmpty(OrgName))
            {
                Message += GetAlert("Name is required.");
                errors++;
            }

            Org existingOrg = DataSession.Query <Org>().Where(x => x.OrgName == OrgName).FirstOrDefault();

            //three possibilities: 1) no org with this name exists, 2) existing is the same as this org, 3) existing is different
            if (existingOrg != null && existingOrg.OrgID != OrgID)
            {
                //there is an existing (and different) org with the same name
                Message += GetAlert("This name is already used by an {0} org.", existingOrg.Active ? "active" : "inactive");
                errors++;
            }

            OrgType orgType = null;

            if (OrgTypeID == 0)
            {
                Message += GetAlert("Type is required.");
                errors++;
            }
            else
            {
                orgType = DataSession.Single <OrgType>(OrgTypeID);
                if (orgType == null)
                {
                    Message += GetAlert("No record found for OrgTypeID {0}", OrgTypeID);
                    errors++;
                }
            }

            Org primary = null;

            if (CanEditPrimaryOrg())
            {
                primary = GetPrimaryOrg();
                if (PrimaryOrg)
                {
                    if (!Active)
                    {
                        Message += GetAlert("The primary org must be active.");
                        errors++;
                    }
                }
                else
                {
                    //make sure there is a primary org
                    if (primary == null)
                    {
                        Message += GetAlert("There must be at least one primary org.");
                        errors++;
                    }
                }
            }

            if (errors > 0)
            {
                return(false);
            }

            Org  org;
            bool originalActive = false;

            if (OrgID == 0)
            {
                //new record
                org = new Org()
                {
                    DefBillAddressID   = 0,
                    DefClientAddressID = 0,
                    DefShipAddressID   = 0,
                    NNINOrg            = NNINOrg,
                    OrgName            = OrgName,
                    OrgType            = orgType,
                    PrimaryOrg         = CanEditPrimaryOrg() && PrimaryOrg
                };

                DataSession.Insert(org); // gets a new OrgID
            }
            else
            {
                org = DataSession.Single <Org>(OrgID);

                if (org == null)
                {
                    Message += GetAlert("No record found for OrgID {0}", OrgID);
                    return(false);
                }

                originalActive = org.Active;

                org.NNINOrg    = NNINOrg;
                org.OrgName    = OrgName;
                org.OrgType    = orgType;
                org.PrimaryOrg = CanEditPrimaryOrg() ? PrimaryOrg : org.PrimaryOrg;
            }

            if (originalActive != Active)
            {
                if (Active)
                {
                    Provider.Data.ActiveLog.Enable(org);
                }
                else
                {
                    Provider.Data.ActiveLog.Disable(org);

                    //need to disable any clients where this was the only active org
                    var clientOrgs = Provider.Data.Client.GetClientOrgs(org.OrgID).Where(x => x.ClientActive);

                    foreach (var co in clientOrgs)
                    {
                        //does this ClientOrg have any other active associations?
                        bool hasAnotherActiveClientOrg = DataSession.Query <ClientOrg>().Any(x => x.Active && x.Client.ClientID == co.ClientID && x.Org.OrgID != co.OrgID);
                        if (!hasAnotherActiveClientOrg)
                        {
                            //no other active ClientOrgs so disable the Client record also
                            var c = DataSession.Single <Client>(co.ClientID);
                            Provider.Data.ActiveLog.Disable(c);
                        }
                    }
                }
            }

            if (CanEditPrimaryOrg() && PrimaryOrg && primary != null)
            {
                primary.PrimaryOrg = false;
                DataSession.SaveOrUpdate(primary);
            }

            OrgID = org.OrgID;

            return(true);
        }
예제 #14
0
        protected void SubmitButton_Command(object sender, CommandEventArgs e)
        {
            ShowErrorMessage(string.Empty);

            try
            {
                int             clientId;
                var             selectedAuthLevel = GetSelectedAuthLevel();
                var             resourceId        = GetCurrentResource().ResourceID;
                ClientAuthLevel refreshAuthLevel  = selectedAuthLevel;

                if (e.CommandName == "Authorize")
                {
                    clientId = int.Parse(ClientsDropDownList.SelectedValue);
                    var rc = new ResourceClient()
                    {
                        ResourceID             = resourceId,
                        ClientID               = clientId,
                        AuthLevel              = selectedAuthLevel,
                        Expiration             = null,
                        EmailNotify            = null,
                        PracticeResEmailNotify = null
                    };

                    SetExpiration(rc);

                    DataSession.Insert(rc);
                    ClearResourceClientsCache();

                    var lname    = string.Empty;
                    var fname    = string.Empty;
                    var splitter = ClientsDropDownList.SelectedItem.Text.Split(',');

                    if (splitter.Length > 0)
                    {
                        lname = splitter[0].Trim();
                    }

                    if (splitter.Length > 1)
                    {
                        fname = splitter[1].Trim();
                    }

                    CurrentClients.Add(new ResourceClientItem()
                    {
                        ResourceClientID = rc.ResourceClientID,
                        ClientID         = clientId,
                        AuthLevel        = selectedAuthLevel,
                        LName            = lname,
                        FName            = fname,
                        Expiration       = rc.Expiration,
                        ContactUrl       = GetContactUrl(clientId),
                        AuthDuration     = GetCurrentResource().AuthDuration,
                        Email            = GetEmailAddress(clientId)
                    });
                }
                else if (e.CommandName == "Modify")
                {
                    clientId = int.Parse(ClientIdHiddenField.Value);
                    var cc = CurrentClients.FirstOrDefault(x => x.ClientID == clientId);
                    if (cc != null)
                    {
                        refreshAuthLevel |= cc.AuthLevel;

                        var rc = DataSession.Single <ResourceClient>(cc.ResourceClientID);
                        rc.AuthLevel = selectedAuthLevel;
                        SetExpiration(rc);

                        DataSession.SaveOrUpdate(rc);
                        ClearResourceClientsCache();

                        cc.AuthLevel  = selectedAuthLevel;
                        cc.Expiration = rc.Expiration;

                        CancelEdit();
                    }
                }

                Fill(refreshAuthLevel);
                FillClients();
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }
예제 #15
0
        public ActionResult Ajax(LNF.Impl.Repository.Data.GlobalSettings model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.SettingName))
                {
                    throw new Exception("Setting name is required.");
                }

                if (model.SettingID == 0)
                {
                    // create new
                    var existing = DataSession.Query <LNF.Impl.Repository.Data.GlobalSettings>().FirstOrDefault(x => x.SettingName == model.SettingName);

                    if (existing != null)
                    {
                        throw new Exception($"A setting with name '{model.SettingName}' already exists.");
                    }

                    DataSession.Insert(new LNF.Impl.Repository.Data.GlobalSettings
                    {
                        SettingName  = model.SettingName,
                        SettingValue = model.SettingValue
                    });
                }
                else
                {
                    var gs = DataSession.Single <LNF.Impl.Repository.Data.GlobalSettings>(model.SettingID);

                    if (gs == null)
                    {
                        throw new Exception($"Cannot find global setting with SettingID = {model.SettingID}");
                    }

                    var existing = DataSession.Query <LNF.Impl.Repository.Data.GlobalSettings>().FirstOrDefault(x => x.SettingName == model.SettingName && x.SettingID != model.SettingID);

                    if (existing != null)
                    {
                        throw new Exception($"A setting with name '{model.SettingName}' already exists.");
                    }

                    gs.SettingName  = model.SettingName;
                    gs.SettingValue = model.SettingValue;

                    DataSession.SaveOrUpdate(gs);
                }

                var items = DataSession.Query <LNF.Impl.Repository.Data.GlobalSettings>();

                return(Json(items));
            }
            catch (Exception ex)
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode             = 500;
                return(Json(new
                {
                    Message = "An error has occurred.",
                    ExceptionMessage = ex.Message,
                    ExceptionType = ex.GetType().ToString(),
                    ex.StackTrace
                }));
            }
        }
 private void SetShowDisclaimerSetting(bool value)
 {
     ShowDisclaimerSetting.SettingValue = value ? "true" : "false";
     DataSession.SaveOrUpdate(ShowDisclaimerSetting);
 }
예제 #17
0
        public bool SaveFeed()
        {
            try
            {
                ErrorMessage = string.Empty;

                DataFeed feed;
                DataFeed existing = GetFeed();

                if (string.IsNullOrEmpty(Guid))
                {
                    //add new feed
                    if (existing != null)
                    {
                        throw new Exception("Alias '" + Alias + "' is already in use");
                    }

                    feed = new DataFeed
                    {
                        FeedGUID        = System.Guid.NewGuid(),
                        FeedAlias       = Alias,
                        FeedName        = Name,
                        FeedDescription = Description,
                        FeedLink        = Link,
                        Private         = Private,
                        Active          = Active,
                        FeedType        = FeedType,
                        FeedQuery       = Query
                    };

                    DataSession.SaveOrUpdate(feed);
                }
                else
                {
                    //update existing feed
                    feed = GetFeedByGuid();

                    if (feed == null)
                    {
                        throw new Exception($"Could not find feed using GUID: {Guid}");
                    }

                    if (existing != null && existing.FeedGUID != feed.FeedGUID)
                    {
                        Alias = feed.FeedAlias;
                        throw new Exception($"Alias '{existing.FeedAlias}' is already in use.");
                    }

                    if (string.IsNullOrEmpty(Alias))
                    {
                        Alias = feed.FeedAlias;
                        throw new Exception("Alias is required.");
                    }

                    if (string.IsNullOrEmpty(Name))
                    {
                        throw new Exception("Name is required.");
                    }

                    feed.FeedAlias         = Alias;
                    feed.FeedName          = Name;
                    feed.FeedDescription   = Description;
                    feed.FeedLink          = Link;
                    feed.Private           = Private;
                    feed.Active            = Active;
                    feed.FeedType          = FeedType;
                    feed.FeedQuery         = Query;
                    feed.DefaultParameters = DefaultParameters;

                    DataSession.SaveOrUpdate(feed);
                }

                return(true);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }
        }