Пример #1
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");
        }
Пример #2
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);
   }
Пример #3
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");
        }
Пример #4
0
        private void AddExpenseToCrm(Form form)
        {
            var client = new CashFlowIntegrationService.CashFlowIntegrationServiceClient();

            CashFlowIntegrationService.Expense expense = new CashFlowIntegrationService.Expense()
            {
                Cost = (double)form.Total,
                Description = form.Name,
                Direction = false
            };

            client.AddExpense(expense);
        }