Example #1
0
        /// <summary>
        /// Gets a list of the roles that a specified user is in for the configured applicationName.
        /// </summary>
        /// <returns>
        /// A string array containing the names of all the roles that the specified user is in for the configured applicationName.
        /// </returns>
        /// <param name="username">The user to return a list of roles for.</param>
        public override string[] GetRolesForUser(string email)
        {
            //Return if the user is not authenticated
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                return null;

            //Return if present in Cache
            var cacheKey = string.Format("UserRoles_{0}", email);
            if (HttpRuntime.Cache[cacheKey] != null)
                return (string[])HttpRuntime.Cache[cacheKey];

            //Get the roles from DB
            var userRoles = new string[] { };
               // userRoles = new[] { email.Split('|')[1] };
            using (var context = new DatabaseContext())
            {
                var user = (from u in context.Accounts
                            where String.Compare(u.Email, email, StringComparison.OrdinalIgnoreCase) == 0
                            select u).FirstOrDefault();

                if (user != null)
                    userRoles = new[] { user.Role.ToString() };
            }

            //Store in cache
            HttpRuntime.Cache.Insert(cacheKey, userRoles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), Cache.NoSlidingExpiration);

            // Return
            return userRoles.ToArray();
        }
Example #2
0
        public Result Register(DatabaseContext db,HttpPostedFileBase file)
        {
            Result res = new Result();

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    // check email exist
                    if (db.Accounts.Any(x => x.Email == this.Account.Email))
                        return res.Fail("This Email has already exist");

                    // if have file's Certificate  , save file
                    if (file != null)
                    {
                        string extension = Path.GetExtension(file.FileName);
                        string fileName = "";
                        string path = "";
                        bool fileInvalid = true;
                        // check if file's exist . If not : save , else : generate another file name
                        do
                        {
                            // generate file's name by guid
                            fileName = Config.CertificateUrl + Guid.NewGuid().ToString() + extension;
                            path = HttpContext.Current.Server.MapPath("~");
                            path = path + fileName;
                            fileInvalid = File.Exists(path + fileName);

                        } while (fileInvalid);

                        file.SaveAs(path);
                        this.Certificate = fileName;
                    }

                    // create account login
                    this.Account.Role = eRole.Investor;
                    db.Accounts.Add(this.Account);
                    db.SaveChanges();
                    if (this.Account.ID == 0)
                    {
                        transaction.Rollback();
                        return res.Fail("Create account fail");
                    }
                    // create trustee
                    db.Trustees.Add(this.Trustee);
                    db.SaveChanges();
                    if (this.Account.ID == 0)
                    {
                        transaction.Rollback();
                        return res.Fail("Create trustee fail");
                    }
                    // create investor information
                    this.UserId = Account.ID;
                    this.TrusteeId = Trustee.ID;
                    db.Investors.Add(this);
                    db.SaveChanges();

                    if (this.ID == 0)
                    {
                        transaction.Rollback();
                        return res.Fail("Create Investor information fail");
                    }
                    transaction.Commit();
                    // send email congratulations for investor
                    Email_Service es = new Email_Service();
                    es.InvestorRegister(this.Account.Email);
                    es.Notification_Register(this.Account.Email,this.Account.Role);

                    return res.Success(this);

                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return res.Fail(ex.Message);
                }
            }
        }
Example #3
0
 public InvestmentService(DatabaseContext context)
 {
     db = context;
 }
Example #4
0
 public InvestmentService()
 {
     db = new DatabaseContext();
 }
Example #5
0
 public ParentService(DatabaseContext context)
 {
     db = context;
 }
Example #6
0
 public ParentService()
 {
     db = new DatabaseContext();
 }
Example #7
0
        /// <summary>
        /// Verifies that the specified user name and password exist in the data source.
        /// </summary>
        /// <returns>
        /// true if the specified email and password are valid; otherwise, false.
        /// </returns>
        /// <param name="email">The name of the user to validate. </param><param name="password">The password for the specified user. </param>
        public override bool ValidateUser(string email, string password)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
                return false;

            using (var context = new DatabaseContext())
            {
                var user = (from u in context.Accounts
                            where String.Compare(u.Email, email, StringComparison.OrdinalIgnoreCase) == 0
                                  && String.Compare(u.Password, password, StringComparison.OrdinalIgnoreCase) == 0
                            select u).FirstOrDefault();

                return user != null;
            }
        }
Example #8
0
        public Result Upsert(DatabaseContext db)
        {
            Result res = new Result();
            ParentService parentService = new ParentService(db);
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    // Get parent by parent's id
                    var resultParent = parentService.GetParentInformationByParentId(ParentId);
                    if (!resultParent.State)
                        return res.Fail(resultParent.Message);

                    Parent parent = (Parent)resultParent.RetVal;
                    // check loan complete
                    if (parent.Status == eBorroweStatus.Funded || parent.Status == eBorroweStatus.Fulfilled)
                        return res.Fail("This investment complete");

                    // get investor in investments for parent
                    var investment = parent.Investments.Where(x => x.InvestorId == InvestorId).FirstOrDefault();
                    // total loan amount
                    var loanWithRate = parent.LoanWithRate;
                    // calculator amount left
                    var amountLeft = loanWithRate
                        - parent.Investments.Sum(x => x.BidAmount)
                        + (investment == null ? 0 : investment.BidAmount);

                    if (this.BidAmount > amountLeft)
                        return res.Fail("Bid amount so large");

                    if (investment == null)
                    {
                        Random ran = new Random();
                        this.BidRate = (decimal)ran.Next(500, 700) / 100;
                        this.LastBidDate = DateTime.Now;
                        this.Status = this.BidAmount == amountLeft ? eInvestmentStatus.Success : eInvestmentStatus.Funding;
                        db.Investments.Add(this);
                        db.SaveChanges();
                    }
                    else
                    {
                        if (this.BidAmount == 0)
                        {
                            db.Entry<Investment>(investment).State = EntityState.Deleted;
                            db.SaveChanges();
                        }
                        else
                        {
                            investment.LastBidDate = DateTime.Now;
                            investment.BidAmount = this.BidAmount;
                            investment.Status = this.BidAmount == amountLeft ? eInvestmentStatus.Success : eInvestmentStatus.Funding;
                            db.Entry<Investment>(investment).State = EntityState.Modified;
                            db.SaveChanges();
                        }

                    }
                    /*Update borrower status*/
                    if (this.BidAmount == amountLeft)
                    {
                        parent.Status = eBorroweStatus.Fulfilled; // funded
                        parent.Investments.ToList().ForEach(a => a.Status = eInvestmentStatus.Success);

                        var listEmail = db.Investments.Where(x=>x.ParentId == parent.ID).Select(b => b.Investor.Account.Email).ToList();

                        es.Notification_InvesmentSuccess(parent.Account.Email, listEmail);
                    }

                    db.SaveChanges();
                    transaction.Commit();
                    return res.Success(this);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return res.Fail(ex.Message);
                }
            }
        }
Example #9
0
 public AccountService(DatabaseContext context)
 {
     db = context;
 }
Example #10
0
 public AccountService()
 {
     db = new DatabaseContext();
 }
Example #11
0
 public SchoolService(DatabaseContext context)
 {
     db = context;
 }
Example #12
0
 public SchoolService()
 {
     db = new DatabaseContext();
 }