public static bool Login(string username, string password) { bool req = false; using (t_elev persoana = new t_elev()) { if (persoana.Email.Equals(username, StringComparison.OrdinalIgnoreCase) && persoana.Parola == password) { req = true; } } if (req == false) { using (t_profesor persoana = new t_profesor()) { if (persoana.Email.Equals(username, StringComparison.OrdinalIgnoreCase) && persoana.Parola == password) { req = true; } } } return(req); }
// POST: api/Elev public HttpResponseMessage Post(HttpRequestMessage request) { var msg = new HttpResponseMessage(); try { var value = request.Content.ReadAsStringAsync().Result; ElevDTO elev = JsonConvert.DeserializeObject <ElevDTO>(value); t_elev elevnou = Mapper.Map <ElevDTO, t_elev>(elev); catalog.Elevi.Add(elevnou); catalog.SaveChanges(); msg.StatusCode = System.Net.HttpStatusCode.OK; msg.Content = new StringContent("Un elev nou a fost adaugat!"); } catch (Exception) { msg.StatusCode = System.Net.HttpStatusCode.BadRequest; msg.Content = new StringContent("Nu s-a putut adauga un elev nou!"); } return(msg); }
//void AddObservatieElev(int elev, int observatie, DatabaseLayer.CatalogContex context) //{ // var newElev = context.Elevi.Where(p => p.Id == elev).FirstOrDefault(); // var newObservatie = context.Observatii.Where(m => m.Id == observatie).FirstOrDefault(); // newElev.Observatii.Add(newObservatie); // //context.Elevi.AddOrUpdate(newElev); // context.SaveChanges(); //} int AddElev(string Nume, string Prenume, DateTime Data_Nasterii, string Telefon, string Email, int Numar_Matricol, int Clasa, DatabaseLayer.CatalogContex context) { var newElev = new t_elev(); newElev.Nume = Nume; newElev.Prenume = Prenume; newElev.Data = Data_Nasterii; newElev.Telefon = Telefon; newElev.Email = Email; newElev.Numar_Matricol = Numar_Matricol; newElev.ClasaID = Clasa; var tempClasa = context.Clase.Where(c => c.Id == Clasa).FirstOrDefault(); newElev.Clasa = tempClasa; //newElev.Note = Note; //newElev.Absente = Absente; //newElev.Observatii = Observatii; context.Elevi.AddOrUpdate(newElev); context.SaveChanges(); int ElevId = newElev.Id; return(ElevId); }
// PUT api/values/5 public HttpResponseMessage Put(int id, HttpRequestMessage request) { var msg = new HttpResponseMessage(); try { var value = request.Content.ReadAsStringAsync().Result; t_observatie obs = catalog.Observatii.Where(obscautat => obscautat.Id == id).FirstOrDefault(); ObservatieDTO obsnou = JsonConvert.DeserializeObject <ObservatieDTO>(value); obs.Id = obsnou.Id; obs.Data = obsnou.Data; obs.Text = obsnou.Text; t_elev elev = catalog.Elevi.Where(elevcautat => elevcautat.Id == obsnou.ElevID).FirstOrDefault(); obs.Elev = elev; t_profesor profesor = catalog.Profesorii.Where(profesorcautat => profesorcautat.Id == obsnou.ProfesorID).FirstOrDefault(); obs.Profesor = profesor; catalog.SaveChanges(); msg.StatusCode = System.Net.HttpStatusCode.OK; msg.Content = new StringContent("Modificarile au fost procesate cu succes!"); } catch (Exception ex) { msg.StatusCode = System.Net.HttpStatusCode.BadRequest; msg.Content = new StringContent("Nu s-au putut executa modificarile dorite!"); } return(msg); }
public HttpResponseMessage CheckCredentials(HttpRequestMessage credentials) { var msg = new HttpResponseMessage(); string userpass = credentials.Content.ReadAsStringAsync().Result; string[] usernamePasswordArray = userpass.Split(':'); string username = usernamePasswordArray[0]; string password = usernamePasswordArray[1]; var utilizator = new Utilizator(); t_elev userelev = catalog.Elevi.Where(elevspecific => elevspecific.Email == username).FirstOrDefault(); if (userelev == null) { t_profesor userprof = catalog.Profesorii.Where(profspecific => profspecific.Email == username).FirstOrDefault(); if (userprof != null && userprof.Parola == password) { utilizator.Tip = ut.profesor; utilizator.Id = userprof.Id; msg.Content = new StringContent(JsonConvert.SerializeObject(utilizator)); } else { msg.StatusCode = HttpStatusCode.Unauthorized; msg.Content = new StringContent("Access denied"); } } else { if (userelev.Parola == password) { utilizator.Tip = ut.elev; utilizator.Id = userelev.Id; msg.Content = new StringContent(JsonConvert.SerializeObject(utilizator)); } else { msg.StatusCode = HttpStatusCode.Unauthorized; msg.Content = new StringContent("Access denied"); } } return(msg); }
// PUT: api/Elev/5 public HttpResponseMessage Put(int id, HttpRequestMessage request) { var msg = new HttpResponseMessage(); try { var value = request.Content.ReadAsStringAsync().Result; t_elev elev = catalog.Elevi.Where(elevcautat => elevcautat.Id == id).FirstOrDefault(); ElevDTO elevnou = JsonConvert.DeserializeObject <ElevDTO>(value); elev.Id = elevnou.Id; elev.Data = elevnou.Data; elev.Email = elevnou.Email; elev.Numar_Matricol = elevnou.Numar_Matricol; elev.Nume = elevnou.Nume; elev.Parola = elevnou.Parola; elev.Prenume = elevnou.Prenume; elev.Telefon = elevnou.Telefon; t_clasa clasa = catalog.Clase.Where(clasacautata => clasacautata.Id == elevnou.ClasaID).FirstOrDefault(); elev.Clasa = clasa; //Lista de Note //Lista de Observatii //Lista de Absente catalog.SaveChanges(); msg.StatusCode = System.Net.HttpStatusCode.OK; msg.Content = new StringContent("Modificarile au fost procesate cu succes!"); } catch (Exception ex) { msg.StatusCode = System.Net.HttpStatusCode.BadRequest; msg.Content = new StringContent("Nu s-au putut executa modificarile dorite!"); } return(msg); }
// DELETE: api/Elev/5 public HttpResponseMessage Delete(int id) { var msg = new HttpResponseMessage(); try { t_elev elev = catalog.Elevi.Where(elevcautat => elevcautat.Id == id).FirstOrDefault(); catalog.Elevi.Remove(elev); catalog.SaveChanges(); msg.StatusCode = System.Net.HttpStatusCode.OK; msg.Content = new StringContent("Stergerea a fost executata cu succes!"); } catch (Exception ex) { msg.StatusCode = System.Net.HttpStatusCode.BadRequest; msg.Content = new StringContent("Elevul dorit nu a putut fi sters!"); } return(msg); }
// PUT: api/Absenta/5 public HttpResponseMessage Put(int id, HttpRequestMessage request) { var msg = new HttpResponseMessage(); try { var value = request.Content.ReadAsStringAsync().Result; t_absenta absenta = catalog.Absente.Where(absentacautata => absentacautata.Id == id).FirstOrDefault(); AbsentaDTO absentanoua = JsonConvert.DeserializeObject <AbsentaDTO>(value); absenta.Id = absentanoua.Id; absenta.Data = absentanoua.Data; //absenta.ElevID = absentanoua.ElevID; //absenta.Elev = absentanoua.Elev; //absenta.MaterieID = absentanoua.MaterieID; //absenta.Materie = absentanoua.Materie; t_elev elev = catalog.Elevi.Where(elevcautat => elevcautat.Id == absentanoua.ElevID).FirstOrDefault(); absenta.Elev = elev; t_materie materie = catalog.Materii.Where(materiecautata => materiecautata.Id == absentanoua.MaterieID).FirstOrDefault(); absenta.Materie = materie; //Lista de elevi catalog.SaveChanges(); msg.StatusCode = System.Net.HttpStatusCode.OK; msg.Content = new StringContent("Modificarile au fost procesate cu succes!"); } catch (Exception ex) { msg.StatusCode = System.Net.HttpStatusCode.BadRequest; msg.Content = new StringContent("Nu s-au putut executa modificarile dorite!"); } return(msg); }