public JObject PutChangeDeliveryManInfo([FromBody] Delivery_man dm) { FastFoodEntities db = new FastFoodEntities(); JObject jRes = new JObject(); DELIVERY_MAN D1 = db.DELIVERY_MAN.FirstOrDefault(d => d.id_delivery_man == dm.id_delivery_man); DELIVERY_MAN D2 = db.DELIVERY_MAN.FirstOrDefault(d => d.email == dm.email && d.id_delivery_man != dm.id_delivery_man); if (D2 != null && D2.email == dm.email) { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Change the email address")); jRes.Add(new JProperty("Message", "This email address is in use by another account.")); } else if (Crypto.VerifyHashedPassword(D1.password, dm.password)) { jRes.Add(new JProperty("Error", false)); D1.firstname = dm.firstname; D1.lastname = dm.lastname; D1.gender = dm.gender; D1.email = dm.email; D1.phone = dm.phone; db.SaveChanges(); Delivery_man d1 = db.DELIVERY_MAN.Select(d => new Delivery_man() { id_delivery_man = d.id_delivery_man, firstname = d.firstname, lastname = d.lastname, gender = d.gender, email = d.email, password = d.password, phone = d.phone, photo = d.photo, transport = d.transport, matricule = d.matricule, latitude = d.latitude, longitude = d.latitude, authorized = d.authorized, state = d.state, id_admin = d.id_admin }).FirstOrDefault(d => d.id_delivery_man == D1.id_delivery_man); // add JWT List <Claim> listClaims = new List <Claim>(); listClaims.Add(new Claim("user_type", "Delivery man")); listClaims.Add(new Claim("id_delivery_man", d1.id_delivery_man.ToString())); jRes.Add(new JProperty("JWT", MyJWT.GenerateJWT(listClaims))); // add id_user jRes.Add(new JProperty("id_delivery_man", d1.id_delivery_man.ToString())); // add user info d1.password = ""; jRes.Add("user_info", d1.toJObject()); } else { jRes.Add(new JProperty("Error", true)); jRes.Add(new JProperty("TitleMessage", "Message")); jRes.Add(new JProperty("Message", "The password is incorrect.")); } return(jRes); }
public JObject DeliveryManSignIn([FromBody] Delivery_man delivery_Man) { FastFoodEntities db = new FastFoodEntities(); JObject j; try { Delivery_man d1 = db.DELIVERY_MAN.Select(d => new Delivery_man() { id_delivery_man = d.id_delivery_man, firstname = d.firstname, lastname = d.lastname, gender = d.gender, email = d.email, password = d.password, phone = d.phone, photo = d.photo, transport = d.transport, matricule = d.matricule, latitude = d.latitude, longitude = d.latitude, authorized = d.authorized, state = d.state, id_admin = d.id_admin }).FirstOrDefault(d => d.email == delivery_Man.email); j = new JObject(); j.Add(new JProperty("API error", false)); if (d1 != null) { if (Crypto.VerifyHashedPassword(d1.password, delivery_Man.password)) { if (d1.authorized) { j.Add(new JProperty("LoggedIn", true)); j.Add(new JProperty("Message", "Connected successfully.")); // add JWT List <Claim> listClaims = new List <Claim>(); listClaims.Add(new Claim("user_type", "Delivery man")); listClaims.Add(new Claim("id_delivery_man", d1.id_delivery_man.ToString())); j.Add(new JProperty("JWT", MyJWT.GenerateJWT(listClaims))); // add id_user j.Add(new JProperty("id_delivery_man", d1.id_delivery_man.ToString())); // add user info d1.password = ""; j.Add("user_info", d1.toJObject()); } else { j.Add(new JProperty("LoggedIn", false)); j.Add(new JProperty("Message", "You are not authorized to deliver.")); } } else { j.Add(new JProperty("LoggedIn", false)); j.Add(new JProperty("Message", "The information is incorrect.")); } } else { j.Add(new JProperty("LoggedIn", false)); j.Add(new JProperty("Message", "The information is incorrect.")); } return(j); } catch (Exception e) { j = new JObject(); j.Add(new JProperty("API error", true)); j.Add(new JProperty("Message", "There is a problem try again.")); return(j); } }