Exemplo n.º 1
0
        //Updates the existing Account Details
        public async Task <IActionResult> OnPutUpdateAccount([FromBody] Models.ActCostAccount obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")))
            {
                try
                {
                    _context.Attach(obj).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Account Changes not saved." + d.InnerException.Message));
                }
            }
            return(new JsonResult("Account Changes not saved."));
        }
Exemplo n.º 2
0
        //Inserts a new Account with details
        public async Task <IActionResult> OnPostInsertAccount([FromBody] Models.ActCostAccount obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")))
            {
                try
                {
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.ActCostAccountID; // Yes it's here
                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Account Not Added." + d.InnerException.Message));
                }
            }

            else
            {
                return(new JsonResult("Account Not Inserted"));
            }
        }