Exemple #1
0
        public static void LogError(string method, string message, bool sendemail)
        {
            try
            {
                //EventLog.WriteEntry(eventSource, string.Format("Error in: {0}\r\nMessage:{1}", new object[] { method, message }), EventLogEntryType.Error);
                
                AppEventLog appLog = new AppEventLog();
                appLog.AppName = "HarperSERVICE";
                appLog.DateCreated = DateTime.Now;
                appLog.Event = "ERROR_LOGGED";
                appLog.Message1 = message;
                appLog.Section = method;
                using (SupportDataDataContext context = new SupportDataDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                {
                    context.AppEventLogs.InsertOnSubmit(appLog);
                    context.SubmitChanges();
                }

                Mailer emailer = new Mailer();
                emailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                    ConfigurationManager.AppSettings["mailservicepwd"],
                    "SERVICE ERROR LOGGED",
                    ConfigurationManager.AppSettings["erroremailsfrom"],
                    ConfigurationManager.AppSettings["erroremailsto"],
                    string.Empty, string.Empty,
                    message,
                    false, ConfigurationManager.AppSettings["erroremailsmtpserver"]);                
            }
            catch { }
        }
        public BaseResponse GetMemberById(string memberId, bool issfgid)
        {
            methodName = "GetMemberByMemberId";
            
            if (!issfgid)
            {
                try
                {
                    using (SupportDataDataContext context = new SupportDataDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                    {
                        memberId = (from a in context.SFG_CustomerNumbers
                                    where a.cusID.ToString() == memberId
                                    select a.SFGCustNum).Single();
                    }
                }
                catch
                {
                    baseResponse.Messages.Add(new Message(MessageSources.AndrewHarper, 0, "ImproperValidationCriteriaException", "Unable to get SFG id for cusid", "", "", null));
                    baseResponse.TypedResponse = new GetMemberResponse();
                    baseResponse.TypedResponse.Success = false;
                    return baseResponse;
                }
            }            
            try
            {
                
                #region validate input
                // All params are required 
                if (memberId.Trim() == "")
                {
                    baseResponse.Messages.Add(new Message("ImproperValidationCriteriaException"));
                    baseResponse.TypedResponse = new GetMemberResponse();
                    baseResponse.TypedResponse.Success = false;
                    return baseResponse;
                }
                #endregion

                GetMemberByMemberIdRequest request = new GetMemberByMemberIdRequest(memberId.Trim(), false);
                baseResponse = Gatekeeper.GetMemberByMemberId(request);
            }
            catch (Exception ex)
            {
                LogMethodError(methodName, ex);
            }
            
            return baseResponse;
        }
Exemple #3
0
        /// <summary>
        /// Deletes all roles for the member then inserts a role for the most recent, active, non-donor subscription
        /// </summary>
        /// <param name="cusid"></param>
        /// <param name="subscriptions"></param>
        /// <returns></returns>
        public static SubscriptionValidation UpdateMemberRole(string username, List<Subscription> subscriptions) 
        {
            SubscriptionValidation validation = new SubscriptionValidation();
            validation.Access = false;
            validation.StatusFlag = "";
            Subscription current = null;
            subscriptions.Sort(delegate (Subscription s1, Subscription s2)
                {
                    return s2.ExpireDate.CompareTo(s1.ExpireDate);
                });
            foreach (Subscription subscription in subscriptions)
            {
                if (!subscription.IsDonor && (subscription.StatusFlag == "P" || subscription.StatusFlag == "0"))
                {
                    validation.StatusFlag = subscription.StatusFlag;
                    current = subscription;
                    break;
                }
            }
            if (current != null)
            {
                using (SupportDataDataContext context = new SupportDataDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                {
                    SupportClasses.Customer customer = null;
                    SupportClasses.MembershipType membershiptype = null;
                    SupportClasses.NetMembership netmembership = null;
                    try
                    {
                        customer = (from a in context.Customers where a.cusUserName == username select a).SingleOrDefault();
                    }
                    catch
                    {
                        throw new MembershipUsernameNotUniqueException();
                    }
                    if (customer == null)
                    {
                        throw new MembershipUnknownUsernameException();
                    }
                    try
                    {
                        membershiptype = (from a in context.MembershipTypes
                                          join b in context.SFG_ProdCodes
                                          on a.mtyCode equals b.IntCode
                                          where b.ExtCode == current.PublicationCode
                                          select a).Single();
                    }
                    catch
                    {
                        throw new Exception(string.Format("Unable to update member's membership type - could not find membership type code {0}.", current.PublicationCode));
                    }

                    try
                    {
                        netmembership = (from a in context.NetMemberships where a.cusID == customer.cusID select a).SingleOrDefault();
                        if (netmembership != null)
                        {
                            context.NetMemberships.DeleteOnSubmit(netmembership);
                            context.SubmitChanges();
                        }
                        netmembership = new NetMembership();
                        netmembership.cusID = customer.cusID;
                        netmembership.mtyCode = membershiptype.mtyCode;
                        netmembership.nmbDateCreated = DateTime.Now;
                        DateTime created;
                        if (!DateTime.TryParse(current.DateEntered, out created))
                        {
                            created = DateTime.Now;
                        }
                        netmembership.nmbDateStart = created;
                        DateTime exp;
                        if (!DateTime.TryParse(current.ExpireDate, out exp))
                        {
                            exp = DateTime.Now.AddMonths(12);
                        }
                        netmembership.nmbDateEnd = exp;
                        context.NetMemberships.InsertOnSubmit(netmembership);
                        context.SubmitChanges();
                    }
                    catch (Exception ex1)
                    {
                        throw new Exception(string.Format("Unable to update member's membership type - error creating netmembership {0}.", ex1.Message));
                    }
                    validation.Access = true;
                }
            }
            return validation; 
        }
Exemple #4
0
        /// <summary>
        /// Creates member at AH from data returned by SFG, returns true if member already exists
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        public static bool CreateMember(Member member) 
        {
            using (SupportDataDataContext context = new SupportDataDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
            {
                var customer = (from a in context.Customers where a.cusUserName == member.UserName select a).SingleOrDefault();
                var sfglink = (from a in context.SFG_CustomerNumbers where a.SFGCustNum == member.MemberId select a).SingleOrDefault();

                if (customer == null && sfglink != null)
                {
                    //someone else already has that sfgid
                    return false;
                }
                try
                {
                    if (customer == null)
                    {
                        AddressCustomer address = new AddressCustomer();
                        address.addAddress1 = member.Address.Address1;
                        address.addAddress2 = member.Address.Address2;
                        address.addAddress3 = member.Address.Address3;
                        address.addCity = member.Address.City;
                        address.addCountry = member.Address.Country;
                        address.addDateCreated = DateTime.Now;
                        address.addDateUpdated = DateTime.Now;
                        address.addPostalCode = member.Address.PostalCode;
                        address.addRegion = member.Address.State;
                        context.AddressCustomers.InsertOnSubmit(address);
                        context.SubmitChanges();

                        var custnum = (from a in context.Customers select a.cusCustNum).Max();
                        int nextcustnum = int.Parse(custnum) + 1;

                        customer = new Customer();
                        customer.addID = address.addID;
                        customer.cusCustNum = nextcustnum.ToString();
                        customer.cusFirstName = member.FirstName;
                        customer.cusLastName = member.LastName;
                        customer.cusCustType = "UNKNOWN";
                        customer.cusPriFirstName = member.FirstName;
                        customer.cusPriLastName = member.LastName;
                        customer.cusPrefix = member.Salutation;
                        customer.cusSuffix = member.Suffix;
                        customer.cusEmail = member.Email;
                        customer.cusUserName = member.UserName;
                        customer.cusIsCharterMem = false;
                        customer.cusIsDeleted = false;
                        customer.cusSex = 'U';
                        customer.cusHasDisplayName = true;
                        customer.cusDisplayName = member.UserName;
                        customer.cusGUID = Guid.NewGuid();
                        context.Customers.InsertOnSubmit(customer);
                        context.SubmitChanges();
                    }
                    if (sfglink == null)
                    {
                        sfglink = new SFG_CustomerNumber();
                        sfglink.SFGCustNum = member.MemberId;
                        sfglink.cusID = customer.cusID;
                        context.SFG_CustomerNumbers.InsertOnSubmit(sfglink);
                        context.SubmitChanges();
                    }
                }
                catch
                {
                    return false;
                }
            }
            return true;
        }