partial void DeleteNetMembership(NetMembership instance);
 partial void UpdateNetMembership(NetMembership instance);
 partial void InsertNetMembership(NetMembership instance);
		private void detach_NetMemberships(NetMembership entity)
		{
			this.SendPropertyChanging();
			entity.MembershipType = null;
		}
		private void attach_NetMemberships(NetMembership entity)
		{
			this.SendPropertyChanging();
			entity.Customer = this;
		}
Example #6
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; 
        }