Exemple #1
0
        public static void RegisterAuthenticationBehavior(HttpRequest request)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;

                        using (CashFlowContext entities = new CashFlowContext())
                        {
                            User user = entities.Users.SingleOrDefault(u => u.UserName == username);

                            roles = user.Roles;
                        }
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Exemple #2
0
 public long?Save(TransferDto transfer)
 {
     if (transfer != null)
     {
         using (var context = new CashFlowContext())
         {
             if (transfer.Id.HasValue)
             {
                 context.Transfer.Update(TransferMapper.Map(transfer));
             }
             else
             {
                 Transfer transferMapped = TransferMapper.Map(transfer);
                 context.Transfer.Add(transferMapped);
                 transfer.Id = transferMapped.Id;
             }
             context.SaveChanges();
         }
         return(transfer.Id);
     }
     else
     {
         return(null);
     }
 }
Exemple #3
0
 public long?Save(TransferDto transfer)
 {
     if (transfer != null)
     {
         using (var context = new CashFlowContext())
         {
             if (transfer.Id.HasValue)
             {
                 TransferSchema transferSchema = context.TransferSchema.SingleOrDefault(t => t.Id == transfer.Id);
                 if (transferSchema != null)
                 {
                     Transfer transferMapped = TransferPendingMapper.Map(transfer);
                     context.Transfer.Add(transferMapped);
                     transfer.Id = transferMapped.Id;
                     transferSchema.LastTransferDate = transferMapped.TransferDate;
                     context.TransferSchema.Update(transferSchema);
                 }
             }
             context.SaveChanges();
         }
         return(transfer.Id);
     }
     else
     {
         return(null);
     }
 }
Exemple #4
0
 public long?Save(AccountDto account)
 {
     if (account != null)
     {
         using (var context = new CashFlowContext())
         {
             if (account.Id.HasValue)
             {
                 context.Account.Update(AccountMapper.Map(account));
             }
             else
             {
                 Account accountMapped = AccountMapper.Map(account);
                 context.Account.Add(accountMapped);
                 account.Id = accountMapped.Id;
                 AccountBalance accountBalance = new AccountBalance();
                 accountBalance.AccountId = account.Id.Value;
                 accountBalance.Balance   = 0;
                 accountBalance.StartDate = DateTime.Now;
                 context.AccountBalance.Add(accountBalance);
             }
             context.SaveChanges();
         }
         return(account.Id);
     }
     else
     {
         return(null);
     }
 }
Exemple #5
0
 public AccountHistoryDto GetAccountHistory(long accountId)
 {
     using (var context = new CashFlowContext())
     {
         DataAccess.EF.Account efAccount = context.Account
                                           .Include(a => a.AccountBalance)
                                           .Include(a => a.TransferAccountFrom).ThenInclude(t => t.AccountTo)
                                           .Include(a => a.TransferAccountTo).ThenInclude(t => t.AccountFrom)
                                           .SingleOrDefault(t => t.Id == accountId);
         if (efAccount != null)
         {
             AccountBalance    lastAccountBalance = efAccount.AccountBalance.OrderByDescending(b => b.StartDate).First();
             AccountHistoryDto account            = AccountHistoryMapper.Map(
                 efAccount,
                 lastAccountBalance,
                 lastAccountBalance.Balance - efAccount.TransferAccountFrom.Sum(t => t.Amount) + efAccount.TransferAccountTo.Sum(t => t.Amount),
                 efAccount.TransferAccountTo.OrderByDescending(t => t.TransferDate),
                 efAccount.TransferAccountFrom.OrderByDescending(t => t.TransferDate));
             return(account);
         }
         else
         {
             return(null);
         }
     }
 }
Exemple #6
0
 public List <TransferSchemaDto> GetAll()
 {
     using (var context = new CashFlowContext())
     {
         List <TransferSchemaDto> transferSchemas = context.TransferSchema.AsEnumerable().Select <DataAccess.EF.TransferSchema, TransferSchemaDto>(t => TransferSchemaMapper.Map(t)).ToList();
         return(transferSchemas);
     }
 }
Exemple #7
0
 public void Delete(long id)
 {
     using (var context = new CashFlowContext())
     {
         var transfer = context.Transfer.FirstOrDefault(t => t.Id == id);
         if (transfer != null)
         {
             context.Remove(transfer);
             context.SaveChanges();
         }
     }
 }
Exemple #8
0
 public void Delete(long id)
 {
     using (var context = new CashFlowContext())
     {
         var Account = context.Account.FirstOrDefault(t => t.Id == id);
         if (Account != null)
         {
             context.Remove(Account);
             context.SaveChanges();
         }
     }
 }
Exemple #9
0
 public TransferSchemaDto GetById(long id)
 {
     using (var context = new CashFlowContext())
     {
         DataAccess.EF.TransferSchema efTransferSchema = context.TransferSchema.SingleOrDefault(t => t.Id == id);
         if (efTransferSchema != null)
         {
             TransferSchemaDto transferSchema = TransferSchemaMapper.Map(efTransferSchema);
             return(transferSchema);
         }
         else
         {
             return(null);
         }
     }
 }
Exemple #10
0
 public PagedList <TransferDto> Get(DataFilter dataFilter)
 {
     using (var context = new CashFlowContext())
     {
         PagedList <TransferDto> transfers = new PagedList <TransferDto>(context.Transfer
                                                                         .Include(t => t.AccountFrom)
                                                                         .Include(t => t.AccountTo)
                                                                         .Filter <DataAccess.EF.Transfer, TransferDto>(dataFilter)
                                                                         .AsEnumerable()
                                                                         .Select <DataAccess.EF.Transfer, TransferDto>(t => TransferMapper.Map(t))
                                                                         .ToList());
         transfers.TotalCount = context.Transfer
                                .Include(t => t.AccountFrom)
                                .Include(t => t.AccountTo).Filter <Transfer, TransferDto>(dataFilter.FilterProperties).Count();
         return(transfers);
     }
 }
Exemple #11
0
 public List <AccountDto> GetAll()
 {
     using (var context = new CashFlowContext())
     {
         IEnumerable <Account> accounts = context.Account
                                          .Include(a => a.AccountBalance)
                                          .Include(a => a.TransferAccountFrom)
                                          .Include(a => a.TransferAccountTo)
                                          .AsEnumerable();
         List <AccountDto> accountDtos = accounts.Select <DataAccess.EF.Account, AccountDto>(a =>
                                                                                             AccountMapper.Map(a,
                                                                                                               a.AccountBalance.OrderByDescending(b => b.StartDate).First().Balance
                                                                                                               - a.TransferAccountFrom.Sum(t => t.Amount)
                                                                                                               + a.TransferAccountTo.Sum(t => t.Amount)))
                                         .ToList();
         return(accountDtos);
     }
 }
Exemple #12
0
 public TransferDto GetById(long id)
 {
     using (var context = new CashFlowContext())
     {
         DataAccess.EF.Transfer efTransfer = context.Transfer
                                             .Include(t => t.AccountFrom)
                                             .Include(t => t.AccountTo)
                                             .SingleOrDefault(t => t.Id == id);
         if (efTransfer != null)
         {
             TransferDto transfer = TransferMapper.Map(efTransfer);
             return(transfer);
         }
         else
         {
             return(null);
         }
     }
 }
Exemple #13
0
        public List <TransferDto> GetAll()
        {
            DateTime pendingDate = DateTime.Now.AddDays(1);

            using (var context = new CashFlowContext())
            {
                List <TransferDto> transfers = context.TransferSchema
                                               .Include(t => t.AccountFrom)
                                               .Include(t => t.AccountTo)
                                               .Where(s => pendingDate > s.TransferStartDate &&
                                                      (pendingDate < s.TransferEndDate || s.TransferEndDate == null) &&
                                                      ((s.TransferPeriod == (int)TransferPeriod.Daily && s.LastTransferDate.HasValue && s.LastTransferDate.Value.Date < pendingDate.AddDays(-1).Date) ||
                                                       (s.TransferPeriod == (int)TransferPeriod.Monthly && s.LastTransferDate.HasValue && s.LastTransferDate.Value.Date < pendingDate.AddMonths(-1).Date) ||
                                                       (s.TransferPeriod == (int)TransferPeriod.Quarterly && s.LastTransferDate.HasValue && s.LastTransferDate.Value.Date < pendingDate.AddMonths(-3).Date) ||
                                                       !s.LastTransferDate.HasValue))
                                               .AsEnumerable().Select <DataAccess.EF.TransferSchema, TransferDto>(t => TransferPendingMapper.Map(t)).ToList();
                return(transfers);
            }
        }
Exemple #14
0
        public ActionResult Index(User model, string returnUrl)
        {
            // Lets first check if the Model is valid or not
            if (ModelState.IsValid)
            {
                using (CashFlowContext entities = new CashFlowContext())
                {
                    string username = model.UserName;
                    string password = model.Password;

                    // Now if our password was enctypted or hashed we would have done the
                    // same operation on the user entered password here, But for now
                    // since the password is in plain text lets just authenticate directly

                    bool userValid = entities.Users.Any(user => user.UserName == username && user.Password == password);

                    // User found in the database
                    if (userValid)
                    {
                        FormsAuthentication.SetAuthCookie(username, false);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                            !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #15
0
 public AccountDto GetById(long accountId)
 {
     using (var context = new CashFlowContext())
     {
         DataAccess.EF.Account efAccount = context.Account
                                           .Include(a => a.AccountBalance)
                                           .Include(a => a.TransferAccountFrom)
                                           .Include(a => a.TransferAccountTo)
                                           .SingleOrDefault(t => t.Id == accountId);
         if (efAccount != null)
         {
             AccountDto Account = AccountMapper.Map(efAccount, efAccount.AccountBalance.OrderByDescending(b => b.StartDate).First().Balance
                                                    - efAccount.TransferAccountFrom.Sum(t => t.Amount)
                                                    + efAccount.TransferAccountTo.Sum(t => t.Amount));
             return(Account);
         }
         else
         {
             return(null);
         }
     }
 }
 public WorkMattersController(CashFlowContext context)
 {
     _context = context;
 }