public ActionResult CreateUpdateFuelExpense(Int32 id)
        {
            var fuelExpenseModel = new FuelExpenseModel();

            if (id > 0)
            {
                var fuelExpense = FarmManagementEntities.FuelExpenses.Single(x => x.Id == id);
                fuelExpenseModel = fuelExpense.ToType <FuelExpense, FuelExpenseModel>();
            }

            return(PartialView("FuelExpensePartial", fuelExpenseModel));
        }
        public ActionResult CreateUpdateFuelExpense(FuelExpenseModel fuelExpenseModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var fuelExpense = new FuelExpense();

            if (fuelExpenseModel.Id > 0)
            {
                fuelExpense = FarmManagementEntities.FuelExpenses.Single(x => x.Id == fuelExpenseModel.Id);
            }

            fuelExpense.FarmId    = fuelExpenseModel.FarmId;
            fuelExpense.AreaId    = fuelExpenseModel.AreaId;
            fuelExpense.AccountId = fuelExpenseModel.AccountId;
            fuelExpense.CropId    = fuelExpenseModel.CropId;

            fuelExpense.FuelId      = fuelExpenseModel.FuelId;
            fuelExpense.Quantity    = fuelExpenseModel.Quantity;
            fuelExpense.Date        = fuelExpenseModel.Date;
            fuelExpense.Description = fuelExpenseModel.Description;

            if (fuelExpenseModel.Id == 0)
            {
                fuelExpense.UserId = fuelExpenseModel.UserId;
                FarmManagementEntities.FuelExpenses.Add(fuelExpense);
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, fuelExpenseModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }