public LanguageM Add(LanguageCreateM model) { try { if (!("Server".Equals(model.Side) || "Client".Equals(model.Side) || "Database".Equals(model.Side))) { throw BadRequest("Side value of framework must be 'Server', 'Client' or 'Database'!"); } if (_language.Any(l => l.Name.Equals(model.Name) && l.Side.Equals(model.Side))) { throw BadRequest("This language is existed!"); } var language = _language.Add(new Language { Name = model.Name, Side = model.Side }); SaveChanges(); return(new LanguageM { Id = language.Id, Name = language.Name, Side = language.Side }); } catch (Exception e) { throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred while add a language!", e, DateTime.Now, "Server", "Service_Language_Add"); } }
public IActionResult Create([FromBody] LanguageCreateM model) { try { return(Created("", _language.Add(model))); } catch (Exception e) { return(GetError(e)); } }