public static void SaveEventBooking(string weChatId, string weChatName, int numberOfMale, int numberOfFemale, string name, 
            string mobile, string desc, string receiptPath, int eventId, out string errorMsg)
        {
            errorMsg = string.Empty;
            int currentTotalMale = 0;
            int currentTotalFemale = 0;
            int maxMale = 0;
            int maxFemale=0;

            GalaxyEntities entity = new GalaxyEntities();

            var currentUser = entity.Users.Where(u=>u.Mobile == mobile).SingleOrDefault();
            var currentEvent = entity.Events.Where(e => e.EventId == eventId).SingleOrDefault();
            var currentUserEventList = entity.UserEvents.Where(e => e.EventId == eventId).ToList();

            maxMale = currentEvent.MaxNumberOfMale;
            maxFemale = currentEvent.MaxNumberOfFemale;

            foreach (var currentUserEvent in currentUserEventList)
            {
                currentTotalMale = currentTotalMale + currentUserEvent.NumberOfMale;
                currentTotalFemale = currentTotalFemale + currentUserEvent.NumberOfFemale;
            }

            // if seperate female and male
            if (currentEvent.SeperateGender)
            {
                // only check if there is number
                if (numberOfMale != 0 || numberOfFemale != 0)
                {
                    if (currentTotalMale + numberOfMale > maxMale)
                    {
                        errorMsg = "对不起, 男生名额已满";
                        return;
                    }
                    if (currentTotalFemale + numberOfFemale > maxFemale)
                    {
                        errorMsg = "对不起, 女生名额已满";
                        return;
                    }
                }
            }
            else
            {
                if (numberOfMale != 0)
                {
                    if (currentTotalMale + numberOfMale > maxMale)
                    {
                        errorMsg = "对不起,名额已满";
                        return;
                    }
                }
            }

            // if user is booked, just update details
            if (currentUserEventList.Count(e => e.User.Mobile == mobile) > 0)
            {
                // delete existing booking, if number is 0
                if (numberOfFemale == 0 && numberOfMale == 0)
                    entity.UserEvents.Remove(currentUserEventList.Where(e => e.User.Mobile == mobile).SingleOrDefault());
                else
                {
                    var currentUserEvent = entity.UserEvents.Where(e =>
                        e.UserId == currentUser.UserId && e.EventId == currentEvent.EventId).SingleOrDefault();
                    currentUserEvent.Description = desc;
                    currentUserEvent.ModifiedTime = DateTime.Now;
                    currentUserEvent.NumberOfFemale = numberOfFemale;
                    currentUserEvent.NumberOfMale = numberOfMale;
                    currentUserEvent.ReceiptPath = receiptPath;
                    currentUserEvent.User.WeChatId = weChatId;
                    currentUserEvent.User.WeChatName = weChatName;
                    currentUserEvent.User.FullName = name;
                }

                entity.SaveChanges();
            }
            // new user booking
            else
            {
                var newUser = new User()
                {
                    WeChatId = weChatId,
                    WeChatName = weChatName,
                    Active = true,
                    FullName = name,
                    UserLevelId = (int)Event.Common.UserLevel.Guest};

                entity.Users.Add(newUser);
                entity.SaveChanges();

                entity.UserEvents.Add(new UserEvent()
                {
                    Description = desc,
                    EventId = eventId,
                    ModifiedTime = DateTime.Now,
                    NumberOfFemale = numberOfFemale,
                    NumberOfMale = numberOfMale,
                    Paid = false,
                    ReceiptPath = receiptPath,
                    RegisteredTime = DateTime.Now,
                    UserId = newUser.UserId
                });
                entity.SaveChanges();
            }
        }
Esempio n. 2
0
        private void BindCustomerData(int eventId)
        {
            GalaxyEntities entity = new GalaxyEntities();

            var datasource = entity.UserEvents.Where(e => e.EventId == eventId).ToList();
            gvCustomer.DataSource = datasource;
            gvCustomer.DataBind();
        }
Esempio n. 3
0
        private bool BindEvent(int eventId)
        {
            int totalNumberMale = 0;
            int totalNumberFemale = 0;
            int paidCountMale = 0;
            int paidCountFemale = 0;

            GalaxyEntities entity = new GalaxyEntities();
            List<User> userList = new List<User>();

            // check if event exists before proceed
            if (entity.Events.Count(e => e.EventId == eventId) == 0)
                return false;

            // get all booked users for this event and bind users to UI
            var userEventList = entity.UserEvents.Where(e=>e.EventId == eventId).ToList();
            if (userEventList != null && userEventList.Count() > 0)
            {
                foreach (var currentUserEvent in userEventList)
                {
                    userList.Add(currentUserEvent.User);

                    if (currentUserEvent.User.Gender.ToUpper().Equals("MALE"))
                    {
                        totalNumberMale++;
                        if (currentUserEvent.Paid)
                            paidCountMale++;
                    }
                    if (currentUserEvent.User.Gender.ToLower().Equals("FEMALE"))
                    {
                        totalNumberFemale++;
                        if (currentUserEvent.Paid)
                            paidCountFemale++;
                    }
                }

                dlCustomer.DataSource = userEventList;
                dlCustomer.DataBind();
            }

            if (totalNumberMale >= Convert.ToInt32(ConfigurationManager.AppSettings["MaximumMaleCount"]))
            {
                lblFail.Text = "名额已满";
                lblMaleFull.Visible = true;
            }

            if (totalNumberFemale >= Convert.ToInt32(ConfigurationManager.AppSettings["MaximumFemaleCount"]))
            {
                lblFail.Text = "名额已满";
                lblFemaleFull.Visible = true;
            }

            // switch UI component based on Event setting
            if (entity.Events.Where(e => e.EventId == eventId).SingleOrDefault().SeperateGender)
            {
                tbTotalSeperateGender.Visible = true;
                tbTotal.Visible = false;

                trNumberOfMale.Visible = true;
                trNumberOfFemale.Visible = true;
                trNumberOfPeople.Visible = false;

                lblCountMale.Text = totalNumberMale.ToString();
                lblPaidCountMale.Text = paidCountMale.ToString();

                lblCountFemale.Text = totalNumberFemale.ToString();
                lblPaidCountFemale.Text = paidCountFemale.ToString();
            }
            else
            {
                tbTotalSeperateGender.Visible = false;
                tbTotal.Visible = true;

                trNumberOfMale.Visible = false;
                trNumberOfFemale.Visible = false;
                trNumberOfPeople.Visible = true;

                lblCount.Text = (totalNumberMale + totalNumberFemale).ToString();
                lblPaid.Text = (paidCountMale + paidCountFemale).ToString();
            }

            return true;
        }