public ActionResult CreateUpdateTransectionPersonalAccount(Int32 id)
        {
            var personalAccountModel = new TransectionPersonalAccountModel();

            personalAccountModel.Date = DateTime.Now;

            return(PartialView("TransectionPersonalAccountPartial", personalAccountModel));
        }
        public ActionResult CreateUpdateTransectionPersonalAccount(TransectionPersonalAccountModel transectionAccountModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var lastTransAccount = FarmManagementEntities.TransectionPersonalAccounts.Where(x => x.UserId == transectionAccountModel.EmployeeId)
                                   .OrderByDescending(x => x.InsertDate).ToList().FirstOrDefault();
            var lastTransAccountBalance = (lastTransAccount == null ? 0 : lastTransAccount.Balance);

            var transectionAccount = new TransectionPersonalAccount();

            transectionAccount.UserId         = transectionAccountModel.EmployeeId;
            transectionAccount.Date           = transectionAccountModel.Date;
            transectionAccount.IsAddedByAdmin = true;

            var isCredit = (TransectionType)transectionAccountModel.AccountTransectionType == TransectionType.Credit;

            if (isCredit)
            {
                transectionAccount.Credit  = transectionAccountModel.Amount;
                transectionAccount.Balance = lastTransAccountBalance + transectionAccountModel.Amount;
            }
            else
            {
                transectionAccount.Debit   = transectionAccountModel.Amount;
                transectionAccount.Balance = lastTransAccountBalance - transectionAccountModel.Amount;
            }

            if (transectionAccountModel.Id == 0)
            {
                transectionAccount.InsertDate = DateTime.Now;
                FarmManagementEntities.TransectionPersonalAccounts.Add(transectionAccount);
            }

            FarmManagementEntities.SaveChanges();

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

            return(ShowSuccessMessage(message));
        }