Example #1
0
        public async Task <IActionResult> Postaccounts([FromBody] accountModel ac)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var accounts = new accounts();

            accounts.account_number   = CHIS.Core.Infrastructure.AccountGenerator.Generate(10);
            accounts.account_type_id  = int.Parse(ac.account_type_id);
            accounts.address1         = ac.address1;
            accounts.address2         = ac.address2;
            accounts.alias            = "";
            accounts.card_holder      = "";
            accounts.card_number      = "";
            accounts.city             = ac.city;
            accounts.country          = ac.country;
            accounts.created          = DateTime.Now;
            accounts.created_by       = "";
            accounts.created_on       = DateTime.Now;
            accounts.credit_card_type = "";
            accounts.credit_limit     = decimal.Parse(ac.credit_limit);
            accounts.email            = ac.email;
            accounts.exp_date         = DateTime.Now;
            accounts.fax        = ac.fax;
            accounts.first_name = ac.first_name;
            accounts.group_name = ac.group_name;
            accounts.hotel_representative_id = int.Parse(ac.hotel_representative_id);
            accounts.last_name       = ac.last_name;
            accounts.modified        = DateTime.Now;
            accounts.opening_balance = 0M;
            accounts.payment_term    = 0M;
            accounts.phone           = ac.phone;
            accounts.postal_code     = ac.postal_code;
            accounts.reg_number      = "";
            accounts.reg_number1     = "";
            accounts.reg_number2     = "";
            accounts.remark          = ac.remark;
            accounts.state           = ac.state;


            _context.accounts.Add(accounts);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Getaccounts", new { id = accounts.id }, accounts));
        }
Example #2
0
        public async Task <IActionResult> Putaccounts([FromRoute] int id, [FromBody] accountModel ac)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != int.Parse(ac.id))
            {
                return(BadRequest());
            }

            var accounts = _context.accounts.Where(a => a.id == id).SingleOrDefault();

            accounts.account_type_id = int.Parse(ac.account_type_id);
            accounts.address1        = ac.address1;
            accounts.address2        = ac.address2;
            accounts.city            = ac.city;
            accounts.country         = ac.country;

            accounts.credit_limit            = decimal.Parse(ac.credit_limit);
            accounts.email                   = ac.email;
            accounts.fax                     = ac.fax;
            accounts.first_name              = ac.first_name;
            accounts.group_name              = ac.group_name;
            accounts.hotel_representative_id = int.Parse(ac.hotel_representative_id);
            accounts.last_name               = ac.last_name;
            accounts.modified                = DateTime.Now;
            accounts.phone                   = ac.phone;
            accounts.postal_code             = ac.postal_code;
            accounts.remark                  = ac.remark;
            accounts.state                   = ac.state;

            _context.SaveChanges();


            return(Ok(accounts));
        }