public async Task <IHttpActionResult> postConsumer(string fName, string lName, string userName, string email, string contactNum, string userPass, string IDnumber, DateTime DOB, string gender, string maritalStatus, string employmentStatus) { DTOuser newUser = await postUser(fName, lName, userName, email, contactNum, userPass, 11, IDnumber); if (newUser.userFirstName == null && newUser.userLastName == null) { if (newUser.userName == "-1") { return(BadRequest("Username taken")); } else if (newUser.userEmail == "-1") { return(BadRequest("email taken")); } else { return(BadRequest("Invalid user")); } } consumer tmp = new consumer(); tmp.User_ID = newUser.User_ID; tmp.consumerDateOfBirth = DOB; tmp.gender = gender; tmp.maritalStatus = maritalStatus; tmp.employmentStatus = employmentStatus; db.consumers.Add(tmp); await db.SaveChangesAsync(); return(Ok()); }
public static consumer updateEntity(consumer entityObjct, DTOconsumer dto) { if (entityObjct == null) { entityObjct = new consumer(); } entityObjct.Consumer_ID = dto.Consumer_ID; entityObjct.User_ID = dto.User_ID; entityObjct.consumerDateOfBirth = dto.consumerDateOfBirth; entityObjct.consumerAddress = dto.consumerAddress; entityObjct.gender = dto.gender; entityObjct.maritalStatus = dto.maritalStatus; entityObjct.topProductCategoriesInterestedIn = dto.topProductCategoriesInterestedIn; entityObjct.homeOwnerType = dto.homeOwnerType; entityObjct.employmentStatus = dto.employmentStatus; entityObjct.grossMonthlyIncome = dto.grossMonthlyIncome; entityObjct.nettMonthlyIncome = dto.nettMonthlyIncome; entityObjct.totalMonthlyExpenses = dto.totalMonthlyExpenses; entityObjct.Location_ID = dto.Location_ID; entityObjct.numDependant = dto.numDependant; entityObjct.numClaims = dto.numClaims; entityObjct.ageGroup_ID = dto.ageGroup_ID; return(entityObjct); }
public async Task <IHttpActionResult> consumerUpdateJustBasicProfile(int userID, string userFirstName, string userLastName, string UserName, string userEmail, string userContactNum, DateTime consumerDateOfBirth, string consumerAddress, string maritalStatus) { //user Table: user toUpdateUser = (from u in db.users where u.User_ID == userID select u).SingleOrDefault(); DTOuser dtoUser = new DTOuser(toUpdateUser); dtoUser.userFirstName = userFirstName; dtoUser.userLastName = userLastName; dtoUser.userName = UserName; dtoUser.userEmail = userEmail; dtoUser.userContactNumber = userContactNum; toUpdateUser = EntityMapper.updateEntity(toUpdateUser, dtoUser); db.Entry(toUpdateUser).State = EntityState.Modified; await db.SaveChangesAsync(); consumer toUpdCons = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault(); DTOconsumer dtoconsumer = new DTOconsumer(toUpdCons); dtoconsumer.consumerDateOfBirth = consumerDateOfBirth; dtoconsumer.consumerAddress = consumerAddress; dtoconsumer.maritalStatus = maritalStatus; toUpdCons = EntityMapper.updateEntity(toUpdCons, dtoconsumer); db.Entry(toUpdCons).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.OK)); }
public async Task <IHttpActionResult> consumerUpdateEntireProfile(int userID, string userFirstName, string userLastName, string UserName, string userEmail, string userContactNum, DateTime consumerDateOfBirth, string consumerAddress, string maritalStatus, string homeOwnerType, string employmentStatus, Nullable <int> numDependants, string topProductsInterestedIn, Nullable <decimal> grossMonthly, Nullable <decimal> nettMonthly, Nullable <decimal> totalExpenses) { //user Table: user toUpdateUser = (from u in db.users where u.User_ID == userID select u).SingleOrDefault(); DTOuser dtoUser = new DTOuser(toUpdateUser); dtoUser.userFirstName = userFirstName; dtoUser.userLastName = userLastName; dtoUser.userName = UserName; dtoUser.userEmail = userEmail; dtoUser.userContactNumber = userContactNum; toUpdateUser = EntityMapper.updateEntity(toUpdateUser, dtoUser); db.Entry(toUpdateUser).State = EntityState.Modified; await db.SaveChangesAsync(); //consumer Table: consumer toUpdate = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault(); DTOconsumer dtoConsumer = new DTOconsumer(toUpdate); dtoConsumer.consumerDateOfBirth = consumerDateOfBirth; dtoConsumer.consumerAddress = consumerAddress; dtoConsumer.maritalStatus = maritalStatus; dtoConsumer.homeOwnerType = homeOwnerType; dtoConsumer.numDependant = numDependants; dtoConsumer.topProductCategoriesInterestedIn = topProductsInterestedIn; dtoConsumer.grossMonthlyIncome = grossMonthly; dtoConsumer.nettMonthlyIncome = nettMonthly; dtoConsumer.totalMonthlyExpenses = totalExpenses; toUpdate = EntityMapper.updateEntity(toUpdate, dtoConsumer); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.OK)); }
public consumer getConsumerByLogin(string email, string password) { consumer consumer = null; consumer = db.consumer.FirstOrDefault(x => x.email == email && x.password == password); return(consumer); }
public int getCustomerID(int UserID) { consumer cons = (from c in db.consumers where c.User_ID == UserID select c).SingleOrDefault(); int consumerId = cons.Consumer_ID; return(consumerId); }
public async Task <DTOconsumer> Postconsumer(DTOconsumer newDTO) { consumer newProd = EntityMapper.updateEntity(null, newDTO); db.consumers.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public async Task <IHttpActionResult> Putconsumer(int ID, DTOconsumer editedDTO) { consumer toUpdate = db.consumers.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> incrementConsumerNumClaims(int consumerID) { consumer toUpdate = (from c in db.consumers where c.Consumer_ID == consumerID select c).SingleOrDefault(); DTOconsumer dtoCons = new DTOconsumer(toUpdate); dtoCons.numClaims = dtoCons.numClaims + 1; toUpdate = EntityMapper.updateEntity(toUpdate, dtoCons); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
// GET: api/Consumer/5 public IHttpActionResult GetConsumerByLogin(JObject loginDetails) { string email = loginDetails["email"].ToObject <string>(); string password = loginDetails["password"].ToObject <string>(); consumer consumer = consumerBL.getConsumerByLogin(email, password); if (consumer == null) { return(Ok(consumer)); } return(Ok(new ConsumerDTO(consumer))); }
public ConsumerDTO(consumer consumer) { id = consumer.id; firstName = consumer.firstName; lastName = consumer.lastName; identityCode = consumer.identityCode; password = consumer.password; tel = consumer.tel; pel = consumer.pel; email = consumer.email; city = consumer.city; street = consumer.street; buildingNumber = consumer.houseNumber; zipCode = consumer.postalCode; }
public DTOconsumerUserProfileInfo(consumer c) { consumerID = c.Consumer_ID; userID = c.User_ID; dateOfBirth = c.consumerDateOfBirth; address = c.consumerAddress; userFirstName = c.user.userFirstName; userLastName = c.user.userLastName; userName = c.user.userName; userEmail = c.user.userEmail; userContactNumber = c.user.userContactNumber; userPassword = c.user.userPassword; isuserActive = c.user.userIsActive; maritalStatus = c.maritalStatus; }
public async Task <IHttpActionResult> putAdditionalSignUpInfo(int userID, string consumerAddress, string homeOwnerType, Nullable <int> numDependants, string topProductsInterestedIn, Nullable <decimal> grossMonthly, Nullable <decimal> nettMonthly, Nullable <decimal> totalExpenses) { consumer toUpdate = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault(); DTOconsumer dtoConsumer = new DTOconsumer(toUpdate); dtoConsumer.consumerAddress = consumerAddress; dtoConsumer.homeOwnerType = homeOwnerType; dtoConsumer.numDependant = numDependants; dtoConsumer.topProductCategoriesInterestedIn = topProductsInterestedIn; dtoConsumer.grossMonthlyIncome = grossMonthly; dtoConsumer.nettMonthlyIncome = nettMonthly; dtoConsumer.totalMonthlyExpenses = totalExpenses; toUpdate = EntityMapper.updateEntity(toUpdate, dtoConsumer); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.OK)); }
public bool getIsHomeOwnerTypeNull(int userID) { consumer cons = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault(); if (cons.homeOwnerType == null) { return(true); } else { return(false); } ////if one of the following are false- know that a legit value has been entered...not null, if they all are true- the IS NULL //if ((!(cons.homeOwnerType.Equals("Renting"))&&(!(cons.homeOwnerType.Equals("Yes")))&&(!(cons.homeOwnerType.Equals("Living with parents")))&&(!(cons.homeOwnerType.Equals("Other"))))) //{ // return true; //} //else //{ // return false; //} }
public ActionResult home(consumer consumer) { SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True"; //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=SouqZone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; //con.ConnectionString = "Data Source=DESKTOPcon.ConnectionString =@"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";J0TTRBH\\SQLEXPRESS;Initial Catalog=souqzone;Integrated Security=True"; con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = con; cmd.CommandText = "getConsumerShops"; cmd.Parameters.AddWithValue("@id", consumer.consumerID); SqlDataReader r = cmd.ExecuteReader(); List <shopOwner> l = new List <shopOwner>(); while (r.Read()) { shopOwner s = new shopOwner(); s.shopName = r["shopName"].ToString(); s.shopImg = r["shopImg"].ToString(); s.consumerID = int.Parse(r["consumerID"].ToString()); s.shopOwnerID = int.Parse(r["shopOwnerID"].ToString()); s.categoryID = int.Parse(r["categoryID"].ToString()); //s.rate = float.Parse(r["rate"].ToString()); Session["consumerID"] = int.Parse(r["consumerID"].ToString()); l.Add(s); } ViewBag.st1 = l; r.Close(); SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.StoredProcedure; cmd2.Connection = con; cmd2.CommandText = "getShopsOffers"; cmd2.Parameters.AddWithValue("@id", consumer.consumerID); SqlDataReader r2 = cmd2.ExecuteReader(); List <shopOwner> l2 = new List <shopOwner>(); while (r2.Read()) { shopOwner s = new shopOwner(); s.shopName = r2["shopName"].ToString(); s.shopImg = r2["shopImg"].ToString(); s.discount = float.Parse(r2["discount"].ToString()); s.city = r2["city"].ToString(); s.categoryID = int.Parse(r2["categoryID"].ToString()); s.shopOwnerID = int.Parse(r2["shopOwnerID"].ToString()); s.categoryType = r2["categoryType"].ToString(); // s.discount = r2["discount"] != null ? double.Parse(r2["discount"].ToString()) : 0; l2.Add(s); } ViewBag.st2 = l2; con.Close(); return(View(l)); }
public ActionResult login(string email, string password) { SqlConnection con = new SqlConnection(); //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=souqzone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True"; con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = con;//بربط ال command على الداتابيز cmd.CommandText = "checkLogin"; cmd.Parameters.AddWithValue("@email ", email); cmd.Parameters.AddWithValue("@password ", password); SqlDataReader r1 = cmd.ExecuteReader(); int personalInfoID, role; if (!r1.HasRows) { ModelState.AddModelError("invalid", "Email or Password is Wrong"); con.Close(); return(View()); } while (r1.Read()) { personalInfoID = int.Parse(r1["personalInfoID"].ToString()); role = int.Parse(r1["role"].ToString()); if (role == 1) { SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.Text; cmd2.CommandText = "select * from consumer where personalInfoID=" + personalInfoID; cmd2.Connection = con; r1.Close(); SqlDataReader r2 = cmd2.ExecuteReader(); consumer s = new consumer(); while (r2.Read()) { s.email = email; s.consumerID = int.Parse(r2["consumerID"].ToString()); s.password = password; s.firstName = r2["firstName"].ToString(); s.country = r2["country"].ToString(); s.city = r2["city"].ToString(); } ViewBag.consumer = s; con.Close(); return(RedirectToAction("home", "Home", s)); } else if (role == 2) { SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.Text; cmd2.CommandText = "select * from supplier where personalInfoID=" + personalInfoID; cmd2.Connection = con; r1.Close(); SqlDataReader r3 = cmd2.ExecuteReader(); supplier s = new supplier(); while (r3.Read()) { s.personalInfoID = int.Parse(r3["personalInfoID"].ToString()); s.email = email; s.supplierID = int.Parse(r3["supplierID"].ToString()); s.password = password; s.name = r3["name"].ToString(); s.country = r3["country"].ToString(); s.city = r3["city"].ToString(); s.supImg = r3["supImg"].ToString(); return(RedirectToAction("xxx", "view", s)); } } else if (role == 3) { SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.Text; cmd2.CommandText = "select * from shopOwner where personalInfoID=" + personalInfoID; cmd2.Connection = con; r1.Close(); SqlDataReader r2 = cmd2.ExecuteReader(); shopOwner s = new shopOwner(); while (r2.Read()) { s.personalInfoID = int.Parse(r2["personalInfoID"].ToString()); s.email = email; s.shopOwnerID = int.Parse(r2["shopOwnerID"].ToString()); s.password = password; s.ownerName = r2["ownerName"].ToString(); s.country = r2["country"].ToString(); s.city = r2["city"].ToString(); s.shopImg = r2["shopImg"].ToString(); s.categoryID = int.Parse(r2["categoryID"].ToString()); con.Close(); return(RedirectToAction("xxx", "view2", s)); } } con.Close(); //return RedirectToAction("Index2", "view2", s); } return(View()); }
public consumer InsertConsumer(consumer consumer) { db.consumer.Add(consumer); db.SaveChanges(); return(db.consumer.FirstOrDefault(x => x.id == consumer.id)); }
public IHttpActionResult GetConsumerById(int id) { consumer consumer = consumerBL.GetConsumerById(id); return(Ok(new ConsumerDTO(consumer))); }
public ActionResult SignUp(uiSignConsumer u) { SqlConnection con = new SqlConnection(); //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=souqzone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True"; con.Open(); if (u.role == 1 && u.password == u.repassword) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = con;//بربط ال command على الداتابيز cmd.CommandText = "addConsumer"; cmd.Parameters.AddWithValue("@consumerName", u.firstName); cmd.Parameters.AddWithValue("@email", u.email); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@country", u.country); cmd.Parameters.AddWithValue("@city", u.city); cmd.Parameters.AddWithValue("@role", u.role); int x = cmd.ExecuteNonQuery(); if (x == 2) { SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.StoredProcedure; cmd2.Connection = con;//بربط ال command على الداتابيز cmd2.CommandText = "getConsumerAll"; cmd2.Parameters.AddWithValue("@email", u.email); SqlDataReader r = cmd2.ExecuteReader(); consumer s = new consumer(); while (r.Read()) { s.personalInfoID = int.Parse(r["personalInfoID"].ToString()); s.email = r["email"].ToString(); s.consumerID = int.Parse(r["consumerID"].ToString()); s.password = r["password"].ToString(); s.firstName = r["firstName"].ToString(); s.country = r["country"].ToString(); s.city = r["city"].ToString(); ViewBag.consumer = s; con.Close(); return(RedirectToAction("home", "Home", s)); } } } else if (u.role == 2 && u.password == u.repassword) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = con;//بربط ال command على الداتابيز cmd.CommandText = "addSupplier"; cmd.Parameters.AddWithValue("@supplierName", u.firstName); cmd.Parameters.AddWithValue("@email", u.email); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@country", u.country); cmd.Parameters.AddWithValue("@city", u.city); cmd.Parameters.AddWithValue("@role", u.role); cmd.Parameters.AddWithValue("@categoryID", u.categoryID); cmd.Parameters.AddWithValue("@lat", u.lat); cmd.Parameters.AddWithValue("@lng", u.lng); int x = cmd.ExecuteNonQuery(); if (x == 2) { SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.StoredProcedure; cmd2.Connection = con;//بربط ال command على الداتابيز cmd2.CommandText = "getSupplierAll"; cmd2.Parameters.AddWithValue("@email", u.email); SqlDataReader r = cmd2.ExecuteReader(); supplier s = new supplier(); while (r.Read()) { s.personalInfoID = int.Parse(r["personalInfoID"].ToString()); s.email = r["email"].ToString(); s.supplierID = int.Parse(r["supplierID"].ToString()); s.password = r["password"].ToString(); s.name = r["name"].ToString(); s.country = r["country"].ToString(); s.city = r["city"].ToString(); s.supImg = r["supImg"].ToString(); s.categoryID = int.Parse(r["categoryID"].ToString()); // ViewBag.supplier = s; return(RedirectToAction("xxx", "view", s)); } } } else if (u.role == 3 && u.password == u.repassword) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = con;//بربط ال command على الداتابيز cmd.CommandText = "addShopOwner"; cmd.Parameters.AddWithValue("@shopName", u.firstName); cmd.Parameters.AddWithValue("@email", u.email); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@country", u.country); cmd.Parameters.AddWithValue("@city", u.city); cmd.Parameters.AddWithValue("@role", u.role); cmd.Parameters.AddWithValue("@categoryID", u.categoryID); cmd.Parameters.AddWithValue("@lat", u.lat); cmd.Parameters.AddWithValue("@lng", u.lng); int x = cmd.ExecuteNonQuery(); if (x == 2) { SqlCommand cmd2 = new SqlCommand(); cmd2.CommandType = System.Data.CommandType.StoredProcedure; cmd2.Connection = con;//بربط ال command على الداتابيز cmd2.CommandText = "getShopOwnerAll"; cmd2.Parameters.AddWithValue("@email", u.email); SqlDataReader r1 = cmd2.ExecuteReader(); shopOwner s = new shopOwner(); while (r1.Read()) { s.personalInfoID = int.Parse(r1["personalInfoID"].ToString()); s.email = r1["email"].ToString(); s.shopOwnerID = int.Parse(r1["shopOwnerID"].ToString()); s.password = r1["password"].ToString(); s.ownerName = r1["ownerName"].ToString(); s.country = r1["country"].ToString(); s.city = r1["city"].ToString(); s.shopImg = r1["shopImg"].ToString(); s.categoryID = int.Parse(r1["categoryID"].ToString()); con.Close(); return(RedirectToAction("xxx", "view2", s)); } } } con.Close(); return(View("errorSignUP")); }
public consumer InsertConsumer(consumer consumer) { return(consumerDL.InsertConsumer(consumer)); }