public HttpResponseMessage updateAccount(String id, Models.MstAccount account) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var accounts = from d in db.MstAccounts where d.Id == Convert.ToInt32(id) select d; if (accounts.Any()) { var updateAccount = accounts.FirstOrDefault(); updateAccount.AccountCode = account.AccountCode; updateAccount.Account = account.Account; updateAccount.AccountTypeId = account.AccountTypeId; updateAccount.AccountCashFlowId = account.AccountCashFlowId; updateAccount.IsLocked = account.IsLocked; updateAccount.UpdatedById = userId; updateAccount.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public Int32 insertAccount(Models.MstAccount account) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); Data.MstAccount newAccount = new Data.MstAccount(); newAccount.AccountCode = account.AccountCode; newAccount.Account = account.Account; newAccount.AccountTypeId = account.AccountTypeId; newAccount.AccountCashFlowId = account.AccountCashFlowId; newAccount.IsLocked = account.IsLocked; newAccount.CreatedById = userId; newAccount.CreatedDateTime = DateTime.Now; newAccount.UpdatedById = userId; newAccount.UpdatedDateTime = DateTime.Now;; db.MstAccounts.InsertOnSubmit(newAccount); db.SubmitChanges(); return(newAccount.Id); } catch { return(0); } }