public async Task <IActionResult> PostNew([FromBody] Event e, string countryID = "") { e.DateEvent = DateTime.Now; dynamic response = new ExpandoObject(); if (ModelState.IsValid) { var country = await _context.Countries.Where(k => k.CountryID == countryID).FirstOrDefaultAsync(); if (country == null) { e.CountryID = ""; } e.CountryID = countryID; response.status = 1; await _context.Events.AddAsync(e); await _context.SaveChangesAsync(); response.status = 1; response.extra = new ExpandoObject(); response.extra.e = e; return(Ok(response)); } else { response.status = 0; response.extra = new ExpandoObject(); response.extra.errorMessage = _modelS.GetErrorMessage(ModelState); return(BadRequest(response)); } }
public async Task <IActionResult> Create([FromBody] News news) { dynamic response = new ExpandoObject(); if (ModelState.IsValid) { response.status = 1; news.DatePub = DateTime.Now; await _context.News.AddAsync(news); await _context.SaveChangesAsync(); response.extra = new ExpandoObject(); response.extra.news = news; return(Ok(response)); } else { response.status = 0; response.extra = new ExpandoObject(); response.extra.news = news; response.extra.errorMessage = _modelS.GetErrorMessage(ModelState); return(BadRequest(response)); } }
public async Task <SuperAdmin> addSuperAdmin(SuperAdmin a) { a.InternationalContestNameC = "IOPS"; a.InternationalContest = _contestRepo.getInternationalContestByEdition(a.InternationalContestEdition); if (getUserByEmail(a.EmailAddress) == null && a.InternationalContest != null) { a.DateAdded = DateTime.UtcNow; this._context.SuperAdmins.Add(a); await _context.SaveChangesAsync(); return(a); } else { return(null); } }
public Country add(Country c) { if (this.isExsist(c.CountryName)) { return(null); } else { if (!_contientRepo.isExsist(c.ContinentID)) { c.Continent = _contientRepo.add(c.ContinentID); _context.SaveChangesAsync(); } _context.Countries.Add(c); _context.SaveChangesAsync(); return(c); } }
public async Task <IActionResult> Create([FromBody] Country country) { dynamic response = new ExpandoObject(); if (ModelState.IsValid) { response.status = 1; response.extra = new ExpandoObject(); response.extra.country = country; Continent c = await _context.Continent.Where(l => l.ContinentID == country.ContinentID).FirstOrDefaultAsync(); if (c == null) { await _context.Continent.AddAsync(new Continent() { ContinentID = country.ContinentID }); await _context.SaveChangesAsync(); } try{ country.Continent = c; await _context.Countries.AddAsync(country); await _context.SaveChangesAsync(); } catch (Exception) { response.status = 0; response.extra.message = "country exsist"; return(BadRequest(response)); } return(Ok(response)); } else { response.status = 0; response.extra = new ExpandoObject(); response.extra.country = country; response.extra.errorMessage = _modelS.GetErrorMessage(ModelState); return(BadRequest(response)); } }
public School addSchool(School i) { if (this._countryRepo.isExsist(i.CountryID)) { if (!isExsist(i.Name)) { this._context.Schools.Add(i); _context.SaveChangesAsync(); return(i); } } return(null); }