Esempio n. 1
0
        public async Task <ActionResult> PostAsync([FromBody] AppSettings item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            try
            {
                var exist = await service.GetAsync(x => x.appname == item.appname);

                if (exist != null)
                {
                    return(Conflict(new Response()
                    {
                        Status = false, Description = "Duplicate record"
                    }));
                }
                var result = await service.AddAsync(item);

                if (result)
                {
                    var newitem = await service.GetAsync(x => x.appname == item.appname);

                    return(StatusCode(201, newitem));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(StatusCode(500, new Response()
                {
                    Status = false, Description = "System error"
                }));
            }
        }