public ActionResult CreateUpdateFertilizerExpense(Int32 id)
        {
            var fertilizerExpenseModel = new FertilizerExpenseModel();

            if (id > 0)
            {
                var fertilizerExpense = FarmManagementEntities.FertilizerExpenses.Single(x => x.Id == id);
                fertilizerExpenseModel = fertilizerExpense.ToType <FertilizerExpense, FertilizerExpenseModel>();
            }

            return(PartialView("FertilizerExpensePartial", fertilizerExpenseModel));
        }
        public ActionResult CreateUpdateFertilizerExpense(FertilizerExpenseModel fertilizerExpenseModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var fertilizerExpense = new FertilizerExpense();

            if (fertilizerExpenseModel.Id > 0)
            {
                fertilizerExpense = FarmManagementEntities.FertilizerExpenses.Single(x => x.Id == fertilizerExpenseModel.Id);
            }

            fertilizerExpense.FarmId    = fertilizerExpenseModel.FarmId;
            fertilizerExpense.AreaId    = fertilizerExpenseModel.AreaId;
            fertilizerExpense.AccountId = fertilizerExpenseModel.AccountId;
            fertilizerExpense.CropId    = fertilizerExpenseModel.CropId;

            fertilizerExpense.FertilizerId     = fertilizerExpenseModel.FertilizerId;
            fertilizerExpense.QuantityInNumber = fertilizerExpenseModel.QuantityInNumber;
            fertilizerExpense.Date             = fertilizerExpenseModel.Date;
            fertilizerExpense.Description      = fertilizerExpenseModel.Description;

            if (fertilizerExpense.Id == 0)
            {
                fertilizerExpense.UserId = fertilizerExpenseModel.UserId;
                FarmManagementEntities.FertilizerExpenses.Add(fertilizerExpense);
            }

            FarmManagementEntities.SaveChanges();

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

            return(ShowSuccessMessage(message));
        }