// POST api/BankAccount public HttpResponseMessage PostBankAccount(BankAccount bankaccount) { if (ModelState.IsValid) { //LoginUser loginUser=new LoginUser(); //long? i = loginUser.UserID; string bankCode=db.Banks.Where(b=>b.BankID==bankaccount.BankID).Select(s=>s.BankCode).SingleOrDefault(); string brakBranchCode=db.BankBranches.Where(b=>b.BankBranchID==bankaccount.BankBranchID).Select(s=>s.BankBranchCode).SingleOrDefault(); ControlCOA controlCOA = new ControlCOA(); bankaccount.AssetCOAID=controlCOA.CreateCOA(bankCode+"-"+brakBranchCode+"-"+bankaccount.BankAccountNumber,3); bankaccount.LiabilityCOAID = controlCOA.CreateCOA(bankCode + "-" + brakBranchCode + "-" + bankaccount.BankAccountNumber, 10002); bankaccount.ExpenseCOAID = controlCOA.CreateCOA(bankCode + "-" + brakBranchCode + "-" + bankaccount.BankAccountNumber, 10004); bankaccount.IncomeCOAID = controlCOA.CreateCOA(bankCode + "-" + brakBranchCode + "-" + bankaccount.BankAccountNumber, 10003); bankaccount.InsertBy = loginUser.UserID; db.BankAccounts.Add(bankaccount); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, bankaccount); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = bankaccount.BankAccountID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// POST api/Collaborator public HttpResponseMessage PostCollaborator(Collaborator collaborator) { if (ModelState.IsValid) { if (WebSecurity.GetUserId(collaborator.EmailID)>0) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { //RegisterModel RM=new RegisterModel(); //RM.UserName=collaborator.Name; //RM.Password="******"; ControlCOA controlCOA = new ControlCOA(); string CollaboratorCode = ""; //long COAID = 0; if (collaborator.IsCustomer == true) { string prefix = db.CustomerTypes.Where(ct => ct.CustomerTypeID == collaborator.CustomerTypeID).Select(s => s.CustomerTypeShortName).SingleOrDefault(); CollaboratorCode = prefix+"-"; collaborator.CustomerCOAID = controlCOA.CreateCOA(collaborator.Title + " " + collaborator.Name, 5); } else if (collaborator.IsSupplier == true) { string prefix = db.SupplierTypes.Where(st => st.SupplierTypeID == collaborator.SupplierTypeID).Select(s => s.SupplierTypeShortName).SingleOrDefault(); CollaboratorCode = prefix+"-"; collaborator.SupplierCOAID = controlCOA.CreateCOA(collaborator.Title + " " + collaborator.Name, 10); } else if (collaborator.IsEmployee == true) { string prefix = db.Departments.Where(st => st.DepartmentID == collaborator.DepartmentID).Select(s => s.DepartmentCode).SingleOrDefault(); CollaboratorCode = prefix; //"EMP-" + DateTime.Now.ToString("yyyyMMdd"); collaborator.EmployeeCOAID = controlCOA.CreateCOA(collaborator.Title + " " + collaborator.Name, 11); } if (CollaboratorCode == "") { CollaboratorCode = "CP-"; } int? MaxCode = Convert.ToInt32((db.Collaborators.Where(r => r.CollaboratorCode.StartsWith(CollaboratorCode)).Select(r => r.CollaboratorCode.Substring(CollaboratorCode.Length, 3)).ToList()).Max()); string CBCode = CollaboratorCode + ((MaxCode + 1).ToString()).PadLeft(3, '0'); collaborator.CollaboratorCode = CBCode; WebSecurity.CreateUserAndAccount(collaborator.EmailID, "123456"); //AccountController acc = new AccountController(); //acc.Register(RM); if (collaborator.IsEmployee == true) { collaborator.UserID = WebSecurity.GetUserId(collaborator.EmailID); } //WebSecurity.InitializeDatabaseConnection(); //WebSecurity.CreateUserAndAccount(, ); collaborator.SalesAssociateID = loginUser.UserID; collaborator.InsertBy = loginUser.UserID; collaborator.InsertDate = DateTime.Now.Date; db.Collaborators.Add(collaborator); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, collaborator); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = collaborator.CollaboratorID })); return response; } } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }