public async Task <IActionResult> Create([FromBody] BackupConfigurationDTO backupDTO)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var backup = mapper.Map <BackupConfigurationDTO, BackupConfiguration>(backupDTO);
                    _context.Add(backup);
                    var res = await _context.SaveChangesAsync();

                    if (res > 0)
                    {
                        var mapped = mapper.Map <BackupConfiguration, BackupConfigurationDTO>(backup);
                        return(new ObjectResult(mapped));
                    }
                }
                catch (Exception ex)
                {
                    this.telemetry.TrackException(ex);
                    return(BadRequest(
                               new { message = ex.Message }
                               ));
                }
            }
            else
            {
                string msg = string.Join("|", ModelState.Values.SelectMany(e => e.Errors).Select(s => s.ErrorMessage));
                return(BadRequest(msg));
            }
            return(BadRequest());
        }
Example #2
0
        public async Task <IActionResult> Create([FromBody] BackupLog log)
        {
            if (ModelState.IsValid)
            {
                _context.Logs.Add(log);
                var res = await _context.SaveChangesAsync();

                if (res > 0)
                {
                    return(new ObjectResult(log.ID));//retun back the new ID
                }
            }
            else
            {
                string msg = string.Join("|", ModelState.Values.SelectMany(e => e.Errors).Select(s => s.ErrorMessage));
                return(BadRequest(msg));
            }
            return(BadRequest());
        }