Esempio n. 1
0
        // 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);
            }
        }
Esempio n. 2
0
        // PUT api/BankAccount/5
        public HttpResponseMessage PutBankAccount(long id, BankAccount bankaccount)
        {
            bankaccount.Bank = null;
            bankaccount.BankBranch = null;
            bankaccount.BankAccountType = null;
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != bankaccount.BankAccountID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            bankaccount.UpdateBy = loginUser.UserID;
            db.Entry(bankaccount).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }