public ActionResult CreateUpdatePersonalAccount(PersonalAccountModel personalAccountModel) { if (!ModelState.IsValid) { return(ShowErrorMessage(GetModelErrors(ModelState))); } var personalAccount = new PersonalAccount(); if (personalAccountModel.Id > 0) { personalAccount = FarmManagementEntities.PersonalAccounts.Single(x => x.Id == personalAccountModel.Id); } personalAccount.UserId = personalAccountModel.EmployeeId; personalAccount.OpeningBalance = personalAccountModel.OpeningBalance; personalAccount.ClosingDate = personalAccountModel.ClosingDate; personalAccount.CreatedDate = personalAccountModel.CreatedDate; if (personalAccountModel.Id == 0) { personalAccount.InsertDate = DateTime.Now; FarmManagementEntities.PersonalAccounts.Add(personalAccount); } else { personalAccount.UpdateDate = DateTime.Now; } FarmManagementEntities.SaveChanges(); var message = string.Format(Constant.SuccessMessage, personalAccountModel.Id > 0 ? "updated" : "added"); return(ShowSuccessMessage(message)); }
public ActionResult CreateUpdatePersonalAccount(Int32 id) { var personalAccountModel = new PersonalAccountModel(); personalAccountModel.CreatedDate = DateTime.Now; if (id > 0) { var personalAccount = FarmManagementEntities.PersonalAccounts.Single(x => x.Id == id); personalAccountModel = personalAccount.ToType <PersonalAccount, PersonalAccountModel>(); personalAccountModel.EmployeeId = personalAccount.UserId; } return(PartialView("PersonalAccountPartial", personalAccountModel)); }