Ejemplo n.º 1
0
        }                                                          //for Chosen Plugin DDL

        public List <string> AddEditActivity(int memberId, int activityID, int activityStatusID, bool?isParticipated, DateTime activityDate, string activityNote, string userId)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            List <string> errs     = new List <string>();
            List <string> warnings = new List <string>();
            string        warning  = String.Empty;

            using (LRCEntities context = new LRCEntities())
            {
                try
                {
                    var existingActivity = context.tb_MemberActivity.Where(t => t.MemberID == memberId && t.ActivityID == activityID).FirstOrDefault();
                    if (existingActivity == null) // Add new activity for selected Member
                    {
                        tb_MemberActivity memberActivity = new tb_MemberActivity
                        {
                            ActivityID       = activityID,
                            MemberID         = memberId,
                            ActivityStatusID = activityStatusID,
                            Participated     = isParticipated
                        };
                        context.tb_MemberActivity.Add(memberActivity);
                    }
                    else //Edit existing activity for selected Member
                    {
                        existingActivity.ActivityStatusID = activityStatusID;
                        existingActivity.Participated     = isParticipated;
                    }

                    tb_Activity activity = context.tb_Activity.Find(activityID);
                    // Change if Activity was edited (activityDate or ActivityNote fields)
                    if (activity.ActivityDate != activityDate || activity.ActivityNote.ToUpper() != activityNote.ToUpper())
                    {
                        activity.ModifiedBy       = userId;
                        activity.ModifiedDateTime = DateTime.UtcNow;
                        activity.ActivityDate     = activityDate;
                        activity.ActivityNote     = activityNote;
                    }
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    return(errs);
                }
            }
            return(errs);
        }
Ejemplo n.º 2
0
        //Check if current AreaName is present in tb_Area already and add it if not
        public static List <string> GetAreaID(string AreaName, out int areaID)
        {
            areaID = 0;
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs    = new List <string>();
            tb_Area       tb_area = new tb_Area();

            using (LRCEntities context = new LRCEntities())
            {
                var areas = context.tb_Area.Where(t => t.AreaName.ToUpper() == AreaName.ToUpper());
                if (areas.Count() == 0)
                {
                    tb_area.AreaName = AreaName;
                    tb_area.AreaDesc = String.Empty; //??? may be add it later with some Edit Area Form
                    context.tb_Area.Add(tb_area);
                    try
                    {
                        context.SaveChanges();
                        areaID = tb_area.AreaID; // new AreaID of added Area
                    }
                    catch (DbEntityValidationException ex)
                    {
                        error.errCode = ErrorDetail.DataImportError;
                        error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                        foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                        {
                            error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                            foreach (DbValidationError err in validationError.ValidationErrors)
                            {
                                error.errMsg += ". " + err.ErrorMessage;
                            }
                        }
                        errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                        return(errs);
                    }
                }
                else
                {
                    //return AreaID of founded Area
                    areaID = areas.FirstOrDefault().AreaID;
                }
            }
            return(errs);
        }
Ejemplo n.º 3
0
        //Assign tb_MemberEmail record for current Member
        public static List <string> AssignEmail(string email, int emailTypeID, bool isEmailPrimary, string source, int mID, string userId)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs = new List <string>();

            using (LRCEntities context = new LRCEntities())
            {
                // Check if email(s) exist for current member
                var memberEmailAddresses = context.tb_MemberEmail.Where(s => s.MemberID == mID).OrderByDescending(s => s.CreatedDateTime).ToArray();

                if (memberEmailAddresses.Count() > 0) //Current member has email(s)
                {
                    int recornNumber = 0;
                    foreach (var me in memberEmailAddresses)
                    {
                        if (++recornNumber <= MvcApplication.MaxRecordsInEmailHistory) //Leaving 10 records only and updating them
                        {
                            if (isEmailPrimary)
                            {
                                me.IsPrimary = false;   //Set IsPrimary to false for all other member email from history
                                if (me.EndDate == null) //EndDate == null means current Member email is actual (isn't record for history)
                                {
                                    me.EndDate = DateTime.UtcNow;
                                }
                            }
                        }
                        else //Remove the excess. In the history we leave only MaxRecordsInEmailHistory = 10 entries
                        {
                            context.tb_MemberEmail.Remove(me);
                        }
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            error.errCode = ErrorDetail.DataImportError;
                            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                            foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                            {
                                error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                                foreach (DbValidationError err in validationError.ValidationErrors)
                                {
                                    error.errMsg += ". " + err.ErrorMessage;
                                }
                            }
                            errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                            return(errs);
                        }
                    }
                }

                //Assign new email to a current Member
                //Check dublicates
                memberEmailAddresses = memberEmailAddresses.Where(s => s.MemberID == mID && s.EmailAddress == email).ToArray();
                if (memberEmailAddresses.Count() == 0) // add new email
                {
                    tb_MemberEmail emailAddress = new tb_MemberEmail()
                    {
                        MemberID        = mID,
                        EmailAddress    = email,
                        IsPrimary       = isEmailPrimary,
                        EmailTypeID     = emailTypeID,
                        Source          = source,
                        CreatedDateTime = DateTime.Now,
                        ModifiedBy      = userId,
                        StartDate       = DateTime.UtcNow,
                        EndDate         = null
                    };
                    if (!isEmailPrimary)
                    {
                        emailAddress.EndDate = DateTime.UtcNow;
                    }
                    context.tb_MemberEmail.Add(emailAddress);
                }
                else // edit old email
                {
                    var emailAddress = context.tb_MemberEmail.Where(s => s.MemberID == mID && s.EmailAddress == email).FirstOrDefault();
                    emailAddress.IsPrimary        = isEmailPrimary;
                    emailAddress.EmailTypeID      = emailTypeID;
                    emailAddress.Source           = source;
                    emailAddress.ModifiedBy       = userId;
                    emailAddress.ModifiedDateTime = DateTime.Now;
                    emailAddress.StartDate        = DateTime.UtcNow;
                    emailAddress.EndDate          = null;
                    if (!isEmailPrimary)
                    {
                        emailAddress.EndDate = DateTime.UtcNow;
                    }
                }

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    return(errs);
                }
                return(errs);
            }
        }
Ejemplo n.º 4
0
        //Get tb_MemberAddress record for current Member
        //Assign MemberID for existing Member or return tb_MemberAddress.MemberID = 0 for new one
        public static List <string> AssignAddress(string _HomeStreet1, string _HomeStreet2, string city, string st, string postal, int addressTypeID,
                                                  bool isAdressPrimary, string source, int sourceID, int mID, string userId)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs = new List <string>();

            //int cityId = GetCityID(city);

            using (LRCEntities context = new LRCEntities())
            {
                // Check if address(es) exist for current member
                var memberAddresses = context.tb_MemberAddress.Where(s => s.MemberID == mID).OrderByDescending(s => s.CreatedDateTime).ToArray();
                var stateNo         = 1;
                try
                {
                    stateNo = context.tb_States.Where(x => x.StateCode.ToUpper() == st.ToUpper()).FirstOrDefault().StateID;
                }
                catch
                {
                    stateNo = 1;
                }

                if (memberAddresses.Count() > 0) //Current member has address(es)
                {
                    int recornNumber = 0;
                    foreach (var ma in memberAddresses)
                    {
                        if (++recornNumber <= MvcApplication.MaxRecordsInAddressHistory) //Leaving 5 records only and updating them
                        {
                            if (isAdressPrimary)
                            {
                                ma.IsPrimary = false;   //Set IsPrimary to false for all of addresses of current member.
                                if (ma.EndDate == null) //EndDate == null means current Member Address is actual (isn't record for history)
                                {
                                    ma.EndDate = DateTime.UtcNow;
                                }
                            }
                        }
                        else //Remove the excess. In the history we leave only MaxRecordsInAddressHistory = 5 entries
                        {
                            context.tb_MemberAddress.Remove(ma);
                        }
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            error.errCode = ErrorDetail.DataImportError;
                            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                            foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                            {
                                error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                                foreach (DbValidationError err in validationError.ValidationErrors)
                                {
                                    error.errMsg += ". " + err.ErrorMessage;
                                }
                            }
                            errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                            return(errs);
                        }
                    }
                }

                //Assign new address to the current Member
                //Check dublicates
                memberAddresses = memberAddresses.Where(s => s.MemberID == mID && s.HomeStreet1 == _HomeStreet1 &&
                                                        s.City == city && s.ZipCode == postal).ToArray();
                if (memberAddresses.Count() == 0) // add new address
                {
                    tb_MemberAddress address = new tb_MemberAddress()
                    {
                        MemberID        = mID,
                        HomeStreet1     = _HomeStreet1,
                        HomeStreet2     = _HomeStreet2,
                        City            = city,
                        ZipCode         = postal,
                        StateID         = stateNo,
                        Country         = "USA",
                        SourceID        = sourceID, // 1 -Card/Form, 2 - Employer
                        Source          = userId,
                        IsPrimary       = isAdressPrimary,
                        AddressTypeID   = addressTypeID,
                        CreatedDateTime = DateTime.Now,
                        ModifiedBy      = userId,
                        StartDate       = DateTime.UtcNow,
                        EndDate         = null
                    };
                    if (!isAdressPrimary)
                    {
                        address.EndDate = DateTime.UtcNow;
                    }

                    context.tb_MemberAddress.Add(address);
                }
                else // edit old address
                {
                    var address = context.tb_MemberAddress.Where(s => s.MemberID == mID && s.HomeStreet1 == _HomeStreet1 &&
                                                                 s.City == city && s.ZipCode == postal).FirstOrDefault();
                    address.HomeStreet2      = _HomeStreet2;
                    address.StateID          = stateNo;
                    address.Country          = "USA";
                    address.SourceID         = sourceID;
                    address.Source           = userId;
                    address.IsPrimary        = isAdressPrimary;
                    address.AddressTypeID    = addressTypeID;
                    address.ModifiedBy       = userId;
                    address.ModifiedDateTime = DateTime.Now;
                    address.StartDate        = DateTime.UtcNow;
                    address.EndDate          = null;
                    if (!isAdressPrimary)
                    {
                        address.EndDate = DateTime.UtcNow;
                    }
                }

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    return(errs);
                }
            }
            return(errs);
        }