Esempio n. 1
0
        /// <summary>
        /// InsertVolunteer
        /// </summary>
        /// <param name="key"></param>
        /// <param name="wardName"></param>
        /// <returns></returns>
        public int InsertVolunteer(string key, string wardName)
        {
            try
            {
                var    user      = context.Auths.Where(@w => @w.Key == key).First();
                var    ward      = context.Wards.Where(@w => @w.Name.Trim() == wardName).First();
                var    zone      = context.Zones.Where(@w => @w.Id == ward.ZoneId).First();
                string topicName = zone.Name.Replace('"', ' ').Trim() + "-" + ward.Name.Replace('"', ' ').Trim();
                var    topic     = context.Topics.Where(@w => @w.Name == topicName).First();

                Volunteer volunteer = new Volunteer()
                {
                    Id     = Guid.NewGuid(),
                    UserId = user.UserId,
                    WardId = ward.Id
                };

                var volunteers = context.Volunteers.Where(@w => @w.UserId == user.UserId);

                if (volunteers != null && volunteers.Count() > 0)
                {
                    return(104);
                }

                context.Volunteers.InsertOnSubmit(volunteer);
                SubmitData();

                TopicUserMap topicUserMap = new TopicUserMap
                {
                    Id      = Guid.NewGuid(),
                    TopicId = topic.Id,
                    UserId  = user.Id
                };

                context.TopicUserMaps.InsertOnSubmit(topicUserMap);
                SubmitData();

                InsertVolunteerRegistrationPoints(user.Id);

                return(215);
            }
            catch (Exception ex)
            {
                return(100);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// InsertVolunteer
        /// </summary>
        /// <param name="key"></param>
        /// <param name="wardName"></param>
        /// <returns></returns>
        public int InsertVolunteer(string key, string wardName)
        {
            try
            {
                var user = context.Auths.Where(@w => @w.Key == key).First();
                var ward = context.Wards.Where(@w => @w.Name.Trim() == wardName).First();
                var zone = context.Zones.Where(@w => @w.Id == ward.ZoneId).First();
                string topicName = zone.Name.Replace('"', ' ').Trim() + "-" + ward.Name.Replace('"', ' ').Trim();
                var topic = context.Topics.Where(@w => @w.Name == topicName).First();

                Volunteer volunteer = new Volunteer()
                {
                    Id = Guid.NewGuid(),
                    UserId = user.UserId,
                    WardId = ward.Id
                };

                var volunteers = context.Volunteers.Where(@w => @w.UserId == user.UserId);

                if (volunteers != null && volunteers.Count() > 0)
                {
                    return 104;
                }

                context.Volunteers.InsertOnSubmit(volunteer);
                SubmitData();

                TopicUserMap topicUserMap = new TopicUserMap
                {
                    Id = Guid.NewGuid(),
                    TopicId = topic.Id,
                    UserId = user.Id
                };

                context.TopicUserMaps.InsertOnSubmit(topicUserMap);
                SubmitData();

                InsertVolunteerRegistrationPoints(user.Id);

                return 215;
            }
            catch (Exception ex)
            {
                return 100;
            }
        }