Esempio n. 1
0
        public ActionResult ApprovedList()
        {
            IEnumerable<Form> forms = null;
            ExpenseEntities db = new ExpenseEntities();

            State state = db.States.Where(s=> s.Name == "Approved").FirstOrDefault();
            Guid userId = Guid.Parse(SessionManager.Get(SessionManager.Keys.UserId).ToString());

            
            if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.Accountant)
            {
                forms = db.Forms.Where(f => f.StateId.Equals(state.Id)).ToList();
            }

            if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.User)
            {
                forms = db.Forms.Where(f => f.StateId.Equals(state.Id) 
                                       && f.OwnerId == userId).ToList();
            }
            if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.Administrator)
            {
                forms = db.Forms.Where(f => f.StateId.Equals(state.Id)).ToList();
            }
            if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.Manager)
            {
                forms = db.Forms.Where(f => f.StateId.Equals(state.Id) && 
                                        f.User.ManagerId == userId).ToList();
            }


            
            return View(forms);

        }
Esempio n. 2
0
        public ActionResult Save(FormCollection form)
        {
            List<string> names, dates, descriptions, costs;

            //Get values
            names = new List<string>(form.GetValues("name[]"));
            dates = new List<string>(form.GetValues("date[]"));
            descriptions = new List<string>(form.GetValues("description[]"));
            costs = new List<string>(form.GetValues("cost[]"));

            string formName = string.Empty;
            //Create new form

            if (!string.IsNullOrEmpty(form["formName"]))
            {
               formName = form["formName"];
            }

                 // TODO: validation
                double totalCost = costs.Sum(c => double.Parse(c));
       
            Models.Form newForm = new Models.Form();
            newForm = FormHelper.Create(formName,totalCost);

          
           

            
            using (ExpenseEntities db = new ExpenseEntities())
            {
                Models.Expense expense;
                for (int i = 0; i < names.Count; i++)
                {
                    
                    expense = new Models.Expense();
                    expense.Id = Guid.NewGuid();
                    expense.Name = names[i];
                    expense.Date = DateTime.Parse(dates[i]);
                    expense.Description = descriptions[i];
                    expense.Cost = int.Parse(costs[i]);
                    expense.FormId = newForm.Id;
                    expense.StateId = newForm.StateId;
                    db.Expenses.Add(expense);
                }
                          
                db.SaveChanges();
            }
           



            return RedirectToAction("New","Expense");
        }
Esempio n. 3
0
        public ActionResult List()
        {
            IEnumerable<Form> forms = null;
            User user = new User();

            ExpenseEntities db = new ExpenseEntities();
                Guid userId = Guid.Parse(SessionManager.Get(SessionManager.Keys.UserId).ToString());

                //Admin can see all forms
                if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.Administrator)
                {
                    forms = db.Forms.ToList();
                   
                }

                //Manager cans see the forms which ones manager is the current manager
                if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.Manager)
                {
                    forms = db.Forms
                                .Where(f => (f.OwnerId == userId
                                            || f.User.ManagerId == userId) 
                                            && f.State.Name != "Paid")
                                            .ToList();
                }

                //User can see only current users forms
                if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.User)
                {
                    forms = db.Forms.Where(f => f.OwnerId == userId).ToList();
                }

                //Accountat can see only approved forms.
                if ((int)SessionManager.Get(SessionManager.Keys.AuthorizeLevel) == AuthorizeLevels.Accountant)
                {
                    forms = db.Forms
                                .Where(f => f.State.Name == "Approved")
                                .ToList();
                }
                                            
                


            return View(forms);
        }
Esempio n. 4
0
        public ActionResult Login(string username , string password)
        {
            ExpenseEntities db = new ExpenseEntities();
            User user = new User();
            user = (User)db.Users.Where(u=> u.Username.Equals(username)&& u.Password.Equals(password)).FirstOrDefault();
            if (user != null)
            {
                SessionManager.Register(SessionManager.Keys.UserId, user.Id);
                SessionManager.Register(SessionManager.Keys.FullName, user.FirstName + " " + user.LastName);
                SessionManager.Register(SessionManager.Keys.Username, user.Username);
                SessionManager.Register(SessionManager.Keys.RoleName, user.Role.Name);
                SessionManager.Register(SessionManager.Keys.LoggedIn, true);
                SessionManager.Register(SessionManager.Keys.AuthorizeLevel, user.Role.AuthorizeLevel);

                return RedirectToAction("Index","Home");
            }

            SessionManager.Register(SessionManager.Keys.LoggedIn, null);
            

            return View();
        }
Esempio n. 5
0
        // GET api/<controller>
        public IEnumerable<CrmExpenseModel> Get()
        {
            List<CrmExpenseModel> model = new List<CrmExpenseModel>();
            
                var client = new CashFlowIntegrationService.CashFlowIntegrationServiceClient();
                var expenses = client.GetExpenses();

                foreach (var e in expenses)
                {
                    CrmExpenseModel crmExpense = new CrmExpenseModel()
                    {
                        Cost = e.Cost,
                        Source = "Crm"


                    };
                    model.Add(crmExpense);
                }

                ExpenseEntities db = new ExpenseEntities();

                foreach (Models.Form f in db.Forms)
                {
                    CrmExpenseModel expenseAppExpense = new CrmExpenseModel()
                    {
                        Cost = f.Total,
                        Source = "ExpenseApp"

                    };
                    model.Add(expenseAppExpense);

                }
            


            
            return model;
        }
Esempio n. 6
0
        public static Models.Form Create(string name, double totalCost)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = SessionManager.Get(SessionManager.Keys.FullName).ToString() + " , " + DateTime.Now.ToString();
            }
            ExpenseEntities db = new ExpenseEntities();
            Models.Form form = new Models.Form();
            form.Id = Guid.NewGuid();
            form.Date = DateTime.Now;
            form.Description = SessionManager.Get(SessionManager.Keys.FullName).ToString() + " Adlı kullanıcının"  + DateTime.Now.ToString() + "Tarihli Formu";
            form.Name = name;
            form.OwnerId = Guid.Parse((SessionManager.Get(SessionManager.Keys.UserId).ToString()));
            State state = (State)db.States.Where(s => s.Name == "Pending").FirstOrDefault();
            form.StateId = state.Id;
            form.Total = (int)totalCost;
            db.Forms.Add(form);
            db.SaveChanges();
          
           

            return form;
        }
Esempio n. 7
0
 public ActionResult List(Guid id)
 { 
     ExpenseEntities db = new ExpenseEntities();
     IEnumerable<Expense.Models.Expense> expenses = db.Expenses.Where(e => e.FormId.Equals(id)).AsEnumerable();
     Form form =  db.Forms.Where(f=> f.Id == id).FirstOrDefault();
     return View(
         new ExpenseViewModel()
         {
             AuthLevel = (SessionManager.Get(SessionManager.Keys.AuthorizeLevel) ?? string.Empty).ToString(),
             Expenses = expenses,
             FormId = id,
             FormState =form.State.Name
         }
     );       
 }
Esempio n. 8
0
        public ActionResult Reject(Guid id)
        {
            Models.Expense expense = new Models.Expense();
            ExpenseEntities db = new ExpenseEntities();
            expense = db.Expenses.Where(e => e.Id == id).FirstOrDefault();
            State state = db.States.Where(s => s.Name == "Reject").FirstOrDefault();
            expense.StateId = state.Id;
            Guid formId = expense.FormId;
            db.SaveChanges();

            return RedirectToAction("List", "Expense", new { id = formId });
        }
Esempio n. 9
0
          public ActionResult Reject(Guid id, string rejectText)
        {
            Expense.Models.Form form = new Expense.Models.Form();
            ExpenseEntities db = new ExpenseEntities();
            form = db.Forms.Where(f=> f.Id == id).FirstOrDefault();
            IEnumerable<Models.Expense> expenses = db.Expenses.Where(e => e.FormId == id).ToList();
            form.ManagerDescription = rejectText;
            State state = db.States.Where(s=> s.Name == "Reject").FirstOrDefault();
            foreach (Models.Expense e in expenses)
            {
                if (e.State.Name != "Approved")
                {
                    e.StateId = state.Id;
                }
            
            }
            form.StateId = state.Id;
            db.SaveChanges();

            return RedirectToAction("List","Form");
        }
Esempio n. 10
0
   public ActionResult Reject(Guid id)
   {
       Expense.Models.Form form = new Expense.Models.Form();
       ExpenseEntities db = new ExpenseEntities();
       form = db.Forms.Where(f=> f.Id == id).FirstOrDefault();
 
       return View(form);
   }
Esempio n. 11
0
        public ActionResult Pay(Guid id)
        {
            Models.Form form = new Models.Form();
            ExpenseEntities db = new ExpenseEntities();
            form = db.Forms.Where(f => f.Id == id).FirstOrDefault();
            State state = db.States.Where(s => s.Name == "Paid").FirstOrDefault();
            form.StateId = state.Id;
            List<Models.Expense> expenses = new List<Models.Expense>();
            expenses = db.Expenses.Where(e => e.FormId == id).ToList();
            foreach (Models.Expense e in expenses)
            {
                e.StateId = state.Id;
            }
            
            db.SaveChanges();

            AddExpenseToCrm(form);

            return RedirectToAction("List", "Form");
        }