Exemplo n.º 1
0
        public ActionResult Edit(Guid id)
        {
            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();
            }

            expense dbItem = RepoExpense.FindByPk(id);
            //expense_item expenseItem = new expense_item();
            List <expense_item> expenseItemList = dbItem.expense_item.Where(x => x.id_expense == dbItem.id).ToList();

            CostFormStub detailStub = new CostFormStub(dbItem, listRent);

            //mobil
            var listItemMobil = expenseItemList.Where(x => x.category == ExpenseItemCategory.VEHICLE.ToString());

            detailStub.ValueVehicle = listItemMobil.Select(x => x.value).FirstOrDefault();
            //supir
            var listItemSupir = expenseItemList.Where(x => x.category == ExpenseItemCategory.DRIVER.ToString());

            detailStub.ValueDriver = listItemSupir.Select(x => x.value).FirstOrDefault();
            //Bensin
            var listItemBBM = expenseItemList.Where(x => x.category == ExpenseItemCategory.GAS.ToString());

            detailStub.ValueGas = listItemBBM.Select(x => x.value).FirstOrDefault();
            //Tol
            var listItemTol = expenseItemList.Where(x => x.category == ExpenseItemCategory.TOLL.ToString());

            detailStub.ValueToll = listItemTol.Select(x => x.value).FirstOrDefault();
            //Parkir
            var listItemParkir = expenseItemList.Where(x => x.category == ExpenseItemCategory.PARKING.ToString());

            detailStub.ValueParking = listItemParkir.Select(x => x.value).FirstOrDefault();
            //BiayaLain
            var listItemBiaya = expenseItemList.Where(x => x.category == ExpenseItemCategory.OTHER.ToString());

            detailStub.ValueOther  = listItemBiaya.Select(x => x.value).FirstOrDefault();
            detailStub.Description = expenseItemList.Select(x => x.description).FirstOrDefault();

            return(View("Form", detailStub));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var model = new CostFormStub();
            StatisticPresentationStub sp = new StatisticPresentationStub();
            //sp = GetStatistic();

            //print
            Guid?printId = null;

            if (TempData["idPrint"] != null)
            {
                printId = TempData["idPrint"] as Nullable <Guid>;
            }
            ViewBag.PrintId = printId;

            model.FillCategoryOptions();
            ViewBag.ListCategory = model.GetCategoryOptions();


            return(View("Index", sp));
        }
Exemplo n.º 3
0
        public ActionResult Create() //get
        {
            Guid?idOwner = (User as CustomPrincipal).IdOwner;
            List <Business.Entities.rent> listRent = new List <rent>();

            Business.Infrastructure.FilterInfo rentFilters = new Business.Infrastructure.FilterInfo {
                Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
            };

            if (idOwner.HasValue)
            {
                //listRent = RepoRent.FindAll().Where(x => x.id_owner == idOwner.Value).ToList();
                //rentFilters.Filters.Add(new Business.Infrastructure.FilterInfo { Field = "id_owner", Operator = "eq", Value = idOwner.ToString() });
                listRent = RepoRent.FindAll(null, null, null, rentFilters);
            }

            CostFormStub formStub = new CostFormStub(listRent);

            formStub.Date = DateTime.Now;
            return(View("Form", formStub));
        }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
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));
            }
        }