Beispiel #1
0
        public static async Task <EventModel> GetEventModel(
            this MemberContext context,
            Guid id,
            DateTime?signedUpBefore,
            int?priority,
            string name,
            bool excludeAcceptedElsewhere,
            bool excludeApprovedElsewhere,
            bool excludeRecommendedElsewhere,
            bool onlyDeniedElsewhere,
            bool onlyRejectedElsewhere,
            bool onlyWaitingListElsewhere)
        {
            var model = await context.Events
                        .Include(e => e.SignupOptions)
                        .AsNoTracking()
                        .FirstOrDefaultAsync(e => e.Id == id);

            if (model == null)
            {
                return(null);
            }

            var signups = await context.EventSignups
                          .Include(s => s.User)
                          .Include(s => s.AuditLog)
                          .ThenInclude(l => l.User)
                          .Include(s => s.Partner)
                          .ThenInclude(p => p.EventSignups)
                          .AsNoTracking()
                          .Expressionify()
                          .Where(e => e.EventId == id)
                          .Filter(signedUpBefore.HasValue, e => e.SignedUpAt < signedUpBefore)
                          .Filter(priority.HasValue, e => e.Priority == priority)
                          .Filter(!string.IsNullOrWhiteSpace(name), e => e.User.NameMatches(name))
                          .Filter(excludeAcceptedElsewhere || excludeApprovedElsewhere || excludeRecommendedElsewhere, e => !e.User.EventSignups
                                  .Where(s => s.Event.SemesterId == model.SemesterId)
                                  .Where(s => s.EventId != e.EventId)
                                  .Any(s => (excludeAcceptedElsewhere && s.Status == Status.AcceptedAndPayed) ||
                                       (excludeApprovedElsewhere && s.Status == Status.Approved) ||
                                       (excludeRecommendedElsewhere && s.Status == Status.Recommended)))
                          .Filter(onlyDeniedElsewhere || onlyRejectedElsewhere || onlyWaitingListElsewhere, e => e.User.EventSignups
                                  .Where(s => s.Event.SemesterId == model.SemesterId)
                                  .Any(s => s.EventId == e.EventId ||
                                       (onlyDeniedElsewhere && s.Status == Status.Denied) ||
                                       (onlyRejectedElsewhere && s.Status == Status.RejectedOrNotPayed) ||
                                       (onlyWaitingListElsewhere && s.Status == Status.WaitingList)))
                          .ToListAsync();

            return(EventModel.Create(model, signups));
        }
Beispiel #2
0
        private string GetPassword(string memberid)
        {
            if (memberid.ToLower().Trim() == DefaultMemberId.ToLower().Trim())
            {
                return(DefaultMemberPwd);
            }
            var member = new MemberContext().MEMBER.FirstOrDefault(o => o.MEMBER_ID == memberid);

            if (member == null)
            {
                throw new Exception("不存在会员号:" + memberid);
            }
            return(member.PASSWD);
        }
Beispiel #3
0
        private async Task <MemberController> GetMemberController(string dbName, Member member)
        {
            var options = new DbContextOptionsBuilder <MemberContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .Options;
            var context = new MemberContext(options);

            context.Members.Add(member);
            await context.SaveChangesAsync();

            var controller = new MemberController(context);

            return(controller);
        }
Beispiel #4
0
        /// <summary>
        /// Login member to app
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public MemberVO LoginMember(string username, string password)
        {
            MemberVO member;

            try
            {
                if (string.IsNullOrWhiteSpace(username))
                {
                    throw new InvalidOperationException(Resource.Er0005);
                }
                Regex rx = new Regex(@"^(?:(?=.*[a-z])(?:(?=.*[A-Z])(?=.*[\d\W])|(?=.*\W)(?=.*\d))|(?=.*\W)(?=.*[A-Z])(?=.*\d)).{8,}$");
                if (!rx.IsMatch(password))
                {
                    throw new InvalidOperationException(Resource.PasswordErrorMessage);
                }
                if (string.IsNullOrWhiteSpace(password))
                {
                    throw new InvalidOperationException(Resource.Er0006);
                }
                if (password.Length < 7)
                {
                    throw new InvalidOperationException(Resource.Er0004);
                }
                using (var ctx = new MemberContext())
                {
                    member = new MemberDA().FindMemberByUserName(ctx, username);
                    if (member == null || member.Id == 0)
                    {
                        throw new Exception(Resource.Er0003);
                    }
                    bool success = Password.ConfirmPassword(password, member.Password);
                    if (!success)
                    {
                        throw new Exception(Resource.Er0004);
                    }
                    else
                    {
                        IRoleBL blRole = new RoleBL();
                        member.Role = blRole.GetRoleById(member.RoleId);
                        MemberStateBL.SetMemberState(member.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(member);
        }
Beispiel #5
0
 public static async Task <IndexModel> GetIndexModel(this MemberContext db, string userId) => await db.Semesters
 .Expressionify()
 .Where(s => s.IsActive())
 .Select(s => new IndexModel
 {
     UserId        = userId,
     SignupOpensAt = s.SignupOpensAt,
     Signups       = s.Courses
                     .SelectMany(c => c.Signups, (e, s) => s)
                     .Where(es => es.UserId == userId)
                     .OrderBy(es => es.Priority)
                     .Select(es => CourseSignupModel.Create(es))
                     .ToList()
 })
 .FirstOrDefaultAsync() ?? new IndexModel();
Beispiel #6
0
        public string ConvertInternal(QueryOperation select, Expression where, QueryOrder order, int?skip, int?take, Graph graph, ModelDetail modelDetail)
        {
            var operationContext = new MemberContext();
            var sb = new CharWriteBuffer();

            try
            {
                Convert(ref sb, select, where, order, skip, take, graph, modelDetail, operationContext);
                return(sb.ToString());
            }
            finally
            {
                sb.Dispose();
            }
        }
Beispiel #7
0
        public ActionResult Add(MemberDatabase.Contact myContact, MemberContext mem)
        {
            //    string connection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            //    MemberContext mem = new MemberContext(connection);
            var unitOfWork = new GenericRepository.UnitOfWork(mem);

            unitOfWork.Repository <Contact>().InsertGraph(myContact);

            unitOfWork.Save();
            List <Contact> memList = unitOfWork.Repository <Contact>().Query().Get().ToList();


            return(View("Index", memList));
        }
        public static ISolrQuery ConditionalQuery(
            this ConditionalExpression expression, 
            Func<Expression,Expression> ifTrueBuilder, 
            Func<Expression, Expression> ifFalseBuilder, 
            MemberContext context)
        {
            ISolrQuery testPositive = expression.Test.GetSolrFilterQuery(context);
            ISolrQuery trueCase = ifTrueBuilder(expression.IfTrue).GetSolrFilterQuery(context);

            ISolrQuery testNegative = testPositive.CreateNotSolrQuery();
            ISolrQuery falseCase = ifFalseBuilder(expression.IfFalse).GetSolrFilterQuery(context);

            return GetMultipleCriteriaQuery(
                GetMultipleCriteriaQuery(testPositive, trueCase, SolrMultipleCriteriaQuery.Operator.AND),
                GetMultipleCriteriaQuery(testNegative, falseCase, SolrMultipleCriteriaQuery.Operator.AND),
                SolrMultipleCriteriaQuery.Operator.OR);
        }
Beispiel #9
0
        public static void Initialize(MemberContext context)
        {
            context.Database.EnsureCreated();

            if (context.Gebruikers.Any())
            {
                return;
            }
            context.Gebruikers.AddRange(
                new Gebruiker {
                Email = "*****@*****.**", Wachtwoord = "melih", Gebruikersnaam = "melih"
            },
                new Gebruiker {
                Email = "*****@*****.**", Wachtwoord = "test", Gebruikersnaam = "test"
            });
            context.SaveChanges();
        }
Beispiel #10
0
        // GET: Contact
        public ActionResult Member(MemberContext mem)
        {
            //ContactList objContacts = new ContactList();

            ////something feels redundant here
            //List<Models.Contact> _objContact = new List<Models.Contact>();
            //_objContact = null; //GetContactList();
            ////objContacts.ContactModel = _objContact;
            //string connection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            //MemberContext mem = new MemberContext(connection);
            var unitOfWork = new GenericRepository.UnitOfWork(mem);

            List <Contact> contactList = unitOfWork.Repository <Contact>().Query().Get().ToList();

            return(View(contactList));
        }
Beispiel #11
0
        public ActionResult Add(MemberDatabase.Group myGroup)
        {
            string connection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            MemberContext mem = new MemberContext(connection);

            var unitOfWork = new GenericRepository.UnitOfWork(mem);

            unitOfWork.Repository <MemberDatabase.Group>().Insert(myGroup);


            unitOfWork.Save();
            List <Group> groupList = unitOfWork.Repository <Group>().Query().Get().ToList();


            return(View("Index", groupList));
        }
Beispiel #12
0
        public ActionResult UploadPhoto(HttpPostedFileBase file, MemberContext mem)
        {
            string serverPath = "";
            string filePath   = "";

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    //useful, but actually not used here. I eventually figured out changing permissions on the folder
                    //this returned mfreedm
                    string user = HttpContext.User.Identity.Name;

                    serverPath = "/Platform/Images/" + file.FileName;
                    filePath   = Server.MapPath(serverPath);
                    file.SaveAs(filePath);
                    ViewBag.Message = "File uploaded successfully";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }

            var unitOfWork = new GenericRepository.UnitOfWork(mem);

            MemberDatabase.File photo = new MemberDatabase.File();

            photo.FilePath    = serverPath;
            photo.FileType    = "Photo";
            photo.UploadDate  = DateTime.Now;
            photo.Description = "uploaded document";

            unitOfWork.Repository <MemberDatabase.File>().Insert(photo);
            unitOfWork.Save();


            List <File> fileList = unitOfWork.Repository <MemberDatabase.File>().Query().Get().ToList();

            return(View("Index", fileList));
        }
        public ActionResult Update(MemberDatabase.Member myMember, MemberContext mem)
        {
            //var unitOfWork = new GenericRepository.UnitOfWork(mem);

            mem.DbSet <Member>().Add(myMember);

            //unitOfWork.Repository<MemberDatabase.Member>().Update(myMember);

            //  mem.Entry(myContact).Property(m => m.Username).IsModified = true;
            //            mem.Entry(myMember).Property(m => m.FirstName).IsModified = true;
            //          mem.Entry(myMember).Property(m => m.LastName).IsModified = true;
            //        mem.Entry(myMember).Property(m => m.Email).IsModified = true;

            mem.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
Beispiel #14
0
        /// <summary>
        /// Get Member by this id
        /// </summary>
        /// <param name="id">id to search member</param>
        /// <returns></returns>
        public MemberVO GetMemberById(int id)
        {
            MemberVO member = null;

            try
            {
                using (var ctx = new MemberContext())
                {
                    IMemberDA da = new MemberDA();
                    member = da.FindMemberById(ctx, id);
                }
            }
            catch
            {
                throw;
            }
            return(member);
        }
Beispiel #15
0
        public ActionResult Update(MemberDatabase.Member myMember, MemberContext mem)
        {
            //    unitOfWork.Repository<MemberDatabase.Member>().Update(myMember);

            //we dont want to expose this, we should handle this in the update method

            //  mem.Entry(myContact).Property(m => m.Username).IsModified = true;
            //       mem.Entry(myMember).Property(m => m.FirstName).IsModified = true;
            ///          mem.Entry(myMember).Property(m => m.LastName).IsModified = true;
//            mem.Entry(myMember).Property(m => m.Email).IsModified = true;

            //   unitOfWork.Save();

            List <Member> memList = mem.DbSet <Member>().ToList();


            return(View("Index", memList));
        }
Beispiel #16
0
        public static bool TryVisitSelect(this MethodCallExpression node, SelectExpressionsCollection options, MemberContext context, out MemberContext newContext)
        {
            newContext = null;
            bool result = node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == Select;

            if (result)
            {
                Expression arg = node.Arguments[1];

                if (arg.NodeType == ExpressionType.Quote)
                {
                    LambdaExpression lambda = (LambdaExpression)node.Arguments[1].StripQuotes();

                    if (lambda.Body is NewExpression selectMember)
                    {
                        newContext = new SelectContext(selectMember, context);
                    }

                    if (lambda.Body is MemberInitExpression memberInit)
                    {
                        newContext = new SelectContext(memberInit, context);
                    }

                    if (lambda.Body is ParameterExpression)
                    {
                        newContext = context;
                        return(result);
                    }

                    if (newContext != null)
                    {
                        options.Fields.Clear();
                        SelectFieldsVisitor visitor = new SelectFieldsVisitor(context, options);
                        visitor.Visit(lambda.Body);

                        return(result);
                    }
                }

                throw new InvalidOperationException($"Unable to translate '{Select}' method.");
            }

            return(result);
        }
Beispiel #17
0
        public ActionResult Update(MemberDatabase.Contact myContact, MemberContext mem)
        {
            //string connection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            //MemberContext mem = new MemberContext(connection);
            var unitOfWork = new GenericRepository.UnitOfWork(mem);

            unitOfWork.Repository <Contact>().Update(myContact);

            //  mem.Entry(myContact).Property(m => m.Username).IsModified = true;
            //mem.Entry(myContact).Property(m => m.FirstName).IsModified = true;
            //mem.Entry(myContact).Property(m => m.LastName).IsModified = true;
            //mem.Entry(myContact).Property(m => m.Email).IsModified = true;

            unitOfWork.Save();
            List <Contact> memList = unitOfWork.Repository <Contact>().Query().Get().ToList();


            return(View("Index", memList));
        }
Beispiel #18
0
        public static async Task <EventInputModel> GetEventInputModel(this MemberContext context, Guid id)
        {
            var model = await context.Events
                        .Include(e => e.SignupOptions)
                        .AsNoTracking()
                        .FirstOrDefaultAsync(e => e.Id == id);

            if (model == null)
            {
                return(null);
            }

            var(signupOpensAtDate, signupOpensAtTime)   = model.SignupOptions.SignupOpensAt.GetLocalDateAndTime();
            var(signupClosesAtDate, signupClosesAtTime) = model.SignupOptions.SignupClosesAt.GetLocalDateAndTime();

            return(new EventInputModel
            {
                Id = model.Id,
                SemesterId = model.SemesterId,
                Title = model.Title,
                Description = model.Description,
                Type = model.Type,
                EnableSignupOpensAt = model.SignupOptions.SignupOpensAt.HasValue,
                SignupOpensAtDate = signupOpensAtDate,
                SignupOpensAtTime = signupOpensAtTime,
                EnableSignupClosesAt = model.SignupOptions.SignupClosesAt.HasValue,
                SignupClosesAtDate = signupClosesAtDate,
                SignupClosesAtTime = signupClosesAtTime,
                PriceForMembers = model.SignupOptions.PriceForMembers,
                PriceForNonMembers = model.SignupOptions.PriceForNonMembers,
                RequiresMembershipFee = model.SignupOptions.RequiresMembershipFee,
                RequiresTrainingFee = model.SignupOptions.RequiresTrainingFee,
                RequiresClassesFee = model.SignupOptions.RequiresClassesFee,
                IncludedInTrainingFee = model.SignupOptions.IncludedInTrainingFee,
                IncludedInClassesFee = model.SignupOptions.IncludedInClassesFee,
                SignupHelp = model.SignupOptions.SignupHelp,
                RoleSignup = model.SignupOptions.RoleSignup,
                RoleSignupHelp = model.SignupOptions.RoleSignupHelp,
                AllowPartnerSignup = model.SignupOptions.AllowPartnerSignup,
                AllowPartnerSignupHelp = model.SignupOptions.AllowPartnerSignupHelp,
                AutoAcceptedSignups = model.SignupOptions.AutoAcceptedSignups
            });
        }
Beispiel #19
0
        public ActionResult Comment(MemberDatabase.Contact myContact, MemberContext mem)
        {
            MemberDatabase.Comment com = new Comment();
            com.comment   = "new comment";
            com.ContactId = myContact.Id;
            com.postDate  = DateTime.Now;
            com.postedBy  = "mfreedm";

            mem.DbSet <Comment>().Add(com);
            mem.SaveChanges();

            MemberDatabase.Repo.ContactRepository repo = new MemberDatabase.Repo.ContactRepository();

            MemberDatabase.Contact contact1 = repo.FindById(myContact.Id);



            return(View("Edit", contact1));
        }
Beispiel #20
0
        public static async Task EditEvent(this MemberContext context, Guid id, Func <Data.Event, Task> action)
        {
            var entry = await context.Events
                        .Include(e => e.SignupOptions)
                        .Include(e => e.Signups)
                        .ThenInclude(s => s.User)
                        .Include(e => e.Signups)
                        .ThenInclude(s => s.AuditLog)
                        .SingleOrDefaultAsync(e => e.Id == id);

            if (entry == null)
            {
                return;
            }

            await action(entry);

            await context.SaveChangesAsync();
        }
Beispiel #21
0
 public String  Deletememberbycolumn(String column, String value)
 {
     try
     {
         MemberContext context = HttpContext.RequestServices.GetService
                                     (typeof(admins_station.Models.MemberContext)) as MemberContext;
         if (context.deleteMember(column, value, connection) > 0)
         {
             return("會員刪除成功");
         }
         else
         {
             return("會員刪除失敗");
         }
     }
     catch (Exception ex)
     {
         return("資料庫操作失敗");
     }
 }
Beispiel #22
0
        public int FindIdByUsername(MemberContext ctx, string username)
        {
            int id = 0;

            try
            {
                var query = (from mem in ctx.Member
                             where mem.Username == username
                             select new
                {
                    mem.Id
                }).Single();
                id = FillItemForDatabase.FillItem(query.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(id);
        }
Beispiel #23
0
 public String Putmemberbycolum(String id, String column, String value)
 {
     try
     {
         MemberContext context = HttpContext.RequestServices.GetService
                                     (typeof(admins_station.Models.MemberContext)) as MemberContext;
         if (context.updateMember(id, column, value, connection) > 0)
         {
             return("會員資料更新成功");
         }
         else
         {
             return("會員資料更新失敗");
         }
     }
     catch (Exception ex)
     {
         return("資料庫沒有" + column + "欄位");
     }
 }
Beispiel #24
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, MemberContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Member API v1"); });


            app.UseHttpsRedirection();
            app.UseCors("MyPolicy");
            app.UseAuthentication();
            app.UseMvc();

            DBInitializer.Initialize(context);
        }
Beispiel #25
0
        public static async Task <EventModel> GetEventModel(this MemberContext context, Guid id)
        {
            var model = await context.Events
                        .Include(e => e.SignupOptions)
                        .Include(e => e.Signups)
                        .ThenInclude(s => s.User)
                        .Include(e => e.Signups)
                        .ThenInclude(s => s.AuditLog)
                        .ThenInclude(l => l.User)
                        .Include(e => e.Signups)
                        .ThenInclude(s => s.Partner)
                        .AsNoTracking()
                        .SingleOrDefaultAsync(e => e.Id == id);

            if (model == null)
            {
                return(null);
            }

            return(EventModel.Create(model));
        }
Beispiel #26
0
 public MemberVO RegisterMember(MemberContext ctx, MemberVO member)
 {
     try
     {
         ctx.Member.Add(member);
         ctx.Cv.Add(new CvVO {
             MemberId = member.Id
         });
         ctx.Person.Add(member.Person);
         ctx.Addresses.Add(member.Person.Address);
         ctx.Emails.Add(member.Person.Email);
         ctx.Phones.Add(member.Person.Phone);
         ctx.Phones.Add(member.Person.Mobile);
         ctx.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(member);
 }
Beispiel #27
0
        public SolrQueryProvider(
            IExecuter <TEntity> operations,
            SolrNetLinqOptions options,
            MemberContext context,
            SelectExpressionsCollection selectExpressions)
        {
            Operations        = operations ?? throw new ArgumentNullException(nameof(operations));
            Options           = options ?? throw new ArgumentNullException(nameof(options));
            SelectExpressions = selectExpressions ?? new SelectExpressionsCollection();

            if (context == null)
            {
                this.MemberContext = MemberContext.ForType <TEntity>();
                this.MemberContext.FieldSerializer = this.Options.SolrFieldSerializer;
                this.MemberContext.MappingManager  = this.Options.MappingManager;
            }
            else
            {
                this.MemberContext = context;
            }
        }
        private async Task <bool> checkLoggedIn()
        {
            var username = HttpContext.Session.GetString("_username");

            if (username == null)
            {
                return(false);
            }

            var session_id = HttpContext.Session.GetString("_sessionid");

            MemberContext context = HttpContext.RequestServices.GetService(typeof(Models.MemberContext)) as MemberContext;

            if (await context.VerifySession(username, session_id))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #29
0
        protected virtual MemberInfo GetMember(MemberContext context)
        {
            switch (context.Expression.ExpressionType)
            {
            case MemberExpressionType.Constant:
                return(null);

            case MemberExpressionType.Identifier:
                return(this.GetMember(context.Owner, ((IdentifierExpression)context.Expression).Name));

            case MemberExpressionType.Method:
                var method = (MethodExpression)context.Expression;
                return(this.GetMember(context.Owner, method.Name));

            case MemberExpressionType.Indexer:
                var indexer = (IndexerExpression)context.Expression;
                return(this.GetMember(context.Owner, string.Empty));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #30
0
        public UrlVO GetUrlByUrl(string url)
        {
            UrlVO model = new UrlVO();

            try
            {
                using (var ctx = new AdminContext())
                {
                    IAdminDA da = new AdminDA();
                    model = da.FindUrlByUrl(ctx, url);
                    using (var ctxM = new MemberContext())
                    {
                        IMemberDA mDa = new MemberDA();
                    }
                }
            }
            catch
            {
                throw;
            }
            return(model);
        }
 public void SetValue(MemberContext context, IObjectContext value)
 {
     _setter(context, value);
 }
 public IObjectContext GetValue(MemberContext context)
 {
     return _getter(context);
 }