Example #1
0
        public async Task <IActionResult> Add([FromBody] Segurados model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var Id = await seguradosRepository.Add(model);

                    if (Id > 0)
                    {
                        var result = new
                        {
                            code = 20000,
                            data = new
                            {
                                id     = Id,
                                mesage = "success"
                            }
                        };

                        return(Ok(result));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
Example #2
0
        public async Task <IActionResult> Update([FromBody] Segurados model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await seguradosRepository.Update(model);

                    var result = new
                    {
                        code = 20000,
                        data = "success"
                    };

                    return(Ok(result));
                }
                catch (Exception ex)
                {
                    if (ex.GetType().FullName ==
                        "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
        public async Task Update(Segurados model)
        {
            if (db != null)
            {
                //Delete that post
                db.Segurados.Update(model);

                //Commit the transaction
                await db.SaveChangesAsync();
            }
        }
        public async Task <int> Add(Segurados model)
        {
            if (db != null)
            {
                await db.Segurados.AddAsync(model);

                await db.SaveChangesAsync();

                return(model.IdSegurado);
            }

            return(0);
        }