Esempio n. 1
0
        public ActionResult Edit(CostFormStub model, bool print = false)
        {
            //bool isNameExist = RepoCar.Find().Where(p => p.name == model.Name).Count() > 0;

            if (ModelState.IsValid)
            {
                expense dbItem = RepoExpense.FindByPk(model.Id);
                //List<expense_item> expenseItemList = dbItem.expense_item.ToList();
                List <expense_item> expenseItemList = dbItem.expense_item.Where(n => n.id_expense == dbItem.id).ToList();
                dbItem = model.SetDbObject(dbItem, (User as CustomPrincipal).Identity.Name);

                try
                {
                    RepoExpense.Save(dbItem);
                    foreach (expense_item items in expenseItemList)
                    {
                        if (items.category.Equals(ExpenseItemCategory.VEHICLE.ToString()))
                        {
                            items.value = model.ValueVehicle;
                            RepoExpense.SaveItem(items);
                        }
                        if (items.category.Equals(ExpenseItemCategory.DRIVER.ToString()))
                        {
                            items.value = model.ValueDriver;
                            RepoExpense.SaveItem(items);
                        }
                        if (items.category.Equals(ExpenseItemCategory.GAS.ToString()))
                        {
                            items.value = model.ValueGas;
                            RepoExpense.SaveItem(items);
                        }
                        if (items.category.Equals(ExpenseItemCategory.TOLL.ToString()))
                        {
                            items.value = model.ValueToll;
                            RepoExpense.SaveItem(items);
                        }
                        if (items.category.Equals(ExpenseItemCategory.PARKING.ToString()))
                        {
                            items.value = model.ValueParking;
                            RepoExpense.SaveItem(items);
                        }
                        if (items.category.Equals(ExpenseItemCategory.OTHER.ToString()))
                        {
                            items.value = model.ValueOther;
                            RepoExpense.SaveItem(items);
                        }

                        items.description = model.Description;
                        RepoExpense.SaveItem(items);
                    }

                    //foreach()
                }
                catch (Exception e)
                {
                    Guid idOwner = (User as CustomPrincipal).IdOwner.Value;
                    List <Business.Entities.rent> listRent = RepoRent.FindAll().Where(x => x.id_owner == idOwner).ToList();
                    model.FillRentOptions(listRent);
                    model.FillCategoryOptions();
                    return(View("Form", model));
                }

                //message
                DisplayFormatHelper dfh = new DisplayFormatHelper();
                string template         = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "EditSuccess").ToString();
                this.SetMessage("Pengeluaran " + model.Date.ToString(dfh.FullDateFormat), template);

                //print flag
                if (print)
                {
                    TempData["idPrint"] = dbItem.id;
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                Guid?idOwner = (User as CustomPrincipal).IdOwner;
                List <Business.Entities.rent> listRent = new List <rent>();
                if (idOwner.HasValue)
                {
                    listRent = RepoRent.FindAll().Where(x => x.id_owner == idOwner.Value).ToList();
                }

                model.FillRentOptions(listRent);
                model.FillCategoryOptions();
                return(View("Form", model));
            }
        }
Esempio n. 2
0
        public ActionResult Create(CostFormStub model, bool print = false)
        {
            //bool isNameExist = RepoCar.Find().Where(p => p.name == model.Name).Count() > 0;

            if (ModelState.IsValid)
            {
                expense      dbItem = new expense();
                expense_item expenseItem;
                dbItem = model.GetDbObject((User as CustomPrincipal).Identity.Name);

                try
                {
                    RepoExpense.Save(dbItem);

                    //save mobil
                    expenseItem = new expense_item {
                        id_expense = dbItem.id, category = ExpenseItemCategory.VEHICLE.ToString(), value = model.ValueVehicle, description = model.Description
                    };
                    RepoExpense.SaveItem(expenseItem);
                    expenseItem = new expense_item {
                        id_expense = dbItem.id, category = ExpenseItemCategory.DRIVER.ToString(), value = model.ValueDriver, description = model.Description
                    };
                    RepoExpense.SaveItem(expenseItem);
                    expenseItem = new expense_item {
                        id_expense = dbItem.id, category = ExpenseItemCategory.GAS.ToString(), value = model.ValueGas, description = model.Description
                    };
                    RepoExpense.SaveItem(expenseItem);
                    expenseItem = new expense_item {
                        id_expense = dbItem.id, category = ExpenseItemCategory.TOLL.ToString(), value = model.ValueToll, description = model.Description
                    };
                    RepoExpense.SaveItem(expenseItem);
                    expenseItem = new expense_item {
                        id_expense = dbItem.id, category = ExpenseItemCategory.PARKING.ToString(), value = model.ValueParking, description = model.Description
                    };
                    RepoExpense.SaveItem(expenseItem);
                    expenseItem = new expense_item {
                        id_expense = dbItem.id, category = ExpenseItemCategory.OTHER.ToString(), value = model.ValueOther, description = model.Description
                    };
                    RepoExpense.SaveItem(expenseItem);
                    //save supir

                    //save ...
                }
                catch (Exception e)
                {
                    Guid?idOwner = (User as CustomPrincipal).IdOwner;
                    List <Business.Entities.rent> listRent = new List <rent>();
                    if (idOwner.HasValue)
                    {
                        listRent = RepoRent.FindAll().Where(x => x.id_owner == idOwner.Value).ToList();
                    }

                    model.FillRentOptions(listRent);
                    model.FillCategoryOptions();
                    return(View("Form", model));
                }

                //message
                DisplayFormatHelper dfh = new DisplayFormatHelper();
                string template         = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString();
                this.SetMessage("Pengeluaran " + model.Date.ToString(dfh.FullDateFormat), template);

                //print flag
                if (print)
                {
                    TempData["idPrint"] = dbItem.id;
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                Guid?idOwner = (User as CustomPrincipal).IdOwner;
                List <Business.Entities.rent> listRent = new List <rent>();
                if (idOwner.HasValue)
                {
                    listRent = RepoRent.FindAll().Where(x => x.id_owner == idOwner.Value).ToList();
                }

                model.FillRentOptions(listRent);
                model.FillCategoryOptions();
                return(View("Form", model));
            }
        }