public HttpResponseMessage updateAccountType(String id, Models.MstAccountType accountType) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var accountTypes = from d in db.MstAccountTypes where d.Id == Convert.ToInt32(id) select d; if (accountTypes.Any()) { var updateAccountType = accountTypes.FirstOrDefault(); updateAccountType.AccountTypeCode = accountType.AccountTypeCode; updateAccountType.AccountType = accountType.AccountType; updateAccountType.AccountCategoryId = accountType.AccountCategoryId; updateAccountType.SubCategoryDescription = accountType.SubCategoryDescription; updateAccountType.IsLocked = accountType.IsLocked; updateAccountType.UpdatedById = userId; updateAccountType.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public Int32 insertAccountType(Models.MstAccountType accountType) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); Data.MstAccountType newAccountType = new Data.MstAccountType(); newAccountType.AccountTypeCode = accountType.AccountTypeCode; newAccountType.AccountType = accountType.AccountType; newAccountType.AccountCategoryId = accountType.AccountCategoryId; newAccountType.SubCategoryDescription = accountType.SubCategoryDescription; newAccountType.IsLocked = accountType.IsLocked; newAccountType.CreatedById = userId; newAccountType.CreatedDateTime = DateTime.Now; newAccountType.UpdatedById = userId; newAccountType.UpdatedDateTime = DateTime.Now; db.MstAccountTypes.InsertOnSubmit(newAccountType); db.SubmitChanges(); return(newAccountType.Id); } catch { return(0); } }