public string Post(LabSpecificna lv) { try { db.LabSpecificna.Add(lv); db.SaveChanges(); return("Added Successfully!!"); } catch (Exception) { return("Failed to Add!!"); } }
public IActionResult Post([FromBody] Student s) { try { if (!string.IsNullOrWhiteSpace(s.Password)) { string hPass = String.Concat(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(s.Password)).Select(x => x.ToString("x2"))); s.Password = hPass; } db.Student.Add(s); db.SaveChanges(); return(Ok()); } catch (Exception) { return(BadRequest()); } }
public async Task <IActionResult> Get([FromQuery] RasporedSearchModel search) { var query = db.Raspored.Include(x => x.StudentNavigation).Include(x => x.LabVezbaNavigation).AsQueryable(); var labQuery = db.LabVezba.AsQueryable(); bool self = false; if (this.IsStudent) { search.studentId = this.StudentId; self = true; } if (search.studentId != null) { query = query.Where(x => x.Student == search.studentId); } query = query.OrderBy(x => x.StudentNavigation.Indeks); var list = query.Select(x => new RasporedModel { Student = new StudentModel { Ime = x.StudentNavigation.Ime, Prezime = x.StudentNavigation.Prezime, Indeks = x.StudentNavigation.Indeks }, LabVezbaSpecificna = new LabVezbaSpecificna { Redosled = x.LabVezbaNavigation.Redosled }, PocetakLaba = x.LabVezbaNavigation.VremeOd ?? DateTime.Now, ZavrsetakLaba = x.LabVezbaNavigation.VremeDo, Ucionica = x.Ucionica, Izmenjen = x.Izmenjen ?? false, NazivLabVezbe = labQuery.Where(lab => lab.Id == x.LabVezbaNavigation.IdLabVezbe).ToArray()[0].Naziv, Id = x.Id }).ToList(); if (self) { await query.ForEachAsync(x => x.Izmenjen = false); db.SaveChanges(); } return(Ok(list)); }