public CustomerDataDTO GetUserById(int id) { using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlCommand comm = conn.CreateCommand()) { comm.CommandText = "select * from CustomerData where CustomerDataId = @id"; comm.Parameters.Clear(); comm.Parameters.AddWithValue("@id", id); conn.Open(); SqlDataReader reader = comm.ExecuteReader(); CustomerDataDTO custData = new CustomerDataDTO { CustomerDataId = (int)reader["CustomerDataId"], CustName = (string)reader["CustName"], CustSurname = (string)reader["CustSurame"], CustEmail = (string)reader["CustEmail"], CustPhone = (int)reader["CustPhone"], CustAddress = (string)reader["CustAddress"], CustPassword = Encoding.ASCII.GetBytes(reader["CustPassword"].ToString()), RoleId = (int)reader["RoleId"] }; return(custData); } }
public async Task <ActionResult <CustomerDTO> > Create(CustomerDataDTO customer) { var result = await this.Mediator.Send(new CreateCustomerCommand { Data = customer }); return(ResponseHelper.ResponseOutcome <CustomerDTO>(result, this)); }
public async Task <ActionResult> Update(int id, CustomerDataDTO customer) { var result = await this.Mediator.Send(new UpdateCustomerCommand { Id = id, Data = customer }); return(ResponseHelper.ResponseOutcome <CustomerDTO>(result, this)); }
public static Customer Map(this CustomerDataDTO dto) => (dto != null) ? new Customer { Address = dto.Address.Address, City = dto.Address.City, ContactPerson = dto.ContactPerson, DateCreated = DateTime.Now, Email = dto.Email, Name = dto.Name, Phone = dto.Phone, Province = dto.Address.Province, ZipCode = dto.Address.ZipCode } : null;
public CustomerDataDTO CreateUser(CustomerDataDTO customer) { using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlCommand comm = conn.CreateCommand()) { Guid salt = Guid.NewGuid(); byte[] newPassword = hash(Encoding.ASCII.GetString(customer.CustPassword), customer.CustSalt.ToString()); comm.CommandText = "insert into CustomerData (CustName, CustSurname, CustEmail, CustPhone, CustAddress, CustPassword, CustSalt, RoleId) output INSERTED.CustomerDataId values (@name, @surname, @email, @phone, @address, @password, @salt, @roleId)"; comm.Parameters.Clear(); comm.Parameters.AddWithValue("@name", customer.CustName); comm.Parameters.AddWithValue("@surname", customer.CustSurname); comm.Parameters.AddWithValue("@email", customer.CustEmail); comm.Parameters.AddWithValue("@phone", customer.CustPhone); comm.Parameters.AddWithValue("@address", customer.CustAddress); comm.Parameters.AddWithValue("@password", newPassword); comm.Parameters.AddWithValue("@salt", salt); comm.Parameters.AddWithValue("@roleId", customer.RoleId); conn.Open(); customer.CustomerDataId = Convert.ToInt32(comm.ExecuteScalar()); return(customer); } }
public bool Login(string username, string password) { using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlCommand comm = conn.CreateCommand()) { comm.CommandText = "select CustEmail, CustPassword, CustSalt from CustomerData where RoleId = 2 AND CustEmail = @email"; comm.Parameters.Clear(); comm.Parameters.AddWithValue("@email", username); //comm.Parameters.AddWithValue("@password", hash(password, )); conn.Open(); SqlDataReader reader = comm.ExecuteReader(); CustomerDataDTO custData = new CustomerDataDTO { CustEmail = (string)reader["CustEmail"], CustPassword = Encoding.ASCII.GetBytes(reader["CustPassword"].ToString()), CustSalt = (System.Guid)reader["CustSalt"], RoleId = (int)reader["RoleId"] }; return(custData.CustEmail != null && custData.CustPassword == hash(password, custData.CustSalt.ToString())); } }
public void CustomerDataDAL() { System.Console.WriteLine("Welcome in Customer CRUD"); while (true) { System.Console.WriteLine("c - Create"); System.Console.WriteLine("r1 - read one"); System.Console.WriteLine("r2 - read all"); System.Console.WriteLine("u - update"); System.Console.WriteLine("d - delete"); System.Console.WriteLine("f - exit"); switch (System.Console.ReadLine()) { case "c": System.Console.WriteLine("Input Customer:"); customer = dal.CreateUser(new CustomerDataDTO { CustName = System.Console.ReadLine(), CustSurname = System.Console.ReadLine(), CustEmail = System.Console.ReadLine(), CustPhone = Convert.ToInt32(System.Console.ReadLine()), CustAddress = System.Console.ReadLine(), CustPassword = Encoding.ASCII.GetBytes(System.Console.ReadLine()), RoleId = Convert.ToInt32(System.Console.ReadLine()) }); System.Console.WriteLine("You add the: Id - " + customer.CustomerDataId + "; Name - " + customer.CustName + " " + customer.CustSurname + "; Email - " + customer.CustEmail + "; Phone - " + customer.CustPhone + "; Address - " + customer.CustAddress + "; Password - " + customer.CustPassword + "; Role Id - " + customer.RoleId); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "r1": System.Console.Write("Choose Id: "); customer = dal.GetUserById(Convert.ToInt32(System.Console.ReadLine())); System.Console.WriteLine("You read the: Id - " + customer.CustomerDataId + "; Name - " + customer.CustName + " " + customer.CustSurname + "; Email - " + customer.CustEmail + "; Phone - " + customer.CustPhone + "; Address - " + customer.CustAddress + "; Password - " + customer.CustPassword + "; Role Id - " + customer.RoleId); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "r2": List <CustomerDataDTO> categories = dal.GetAllUsers(); for (int i = 0; i < categories.Count; i++) { System.Console.WriteLine("You read the: Id - " + customer.CustomerDataId + "; Name - " + customer.CustName + " " + customer.CustSurname + "; Email - " + customer.CustEmail + "; Phone - " + customer.CustPhone + "; Address - " + customer.CustAddress + "; Password - " + customer.CustPassword + "; Role Id - " + customer.RoleId); } System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "u": System.Console.WriteLine("Update Name:"); customer = dal.UpdateUser(new CustomerDataDTO { CustName = System.Console.ReadLine(), CustSurname = System.Console.ReadLine(), CustEmail = System.Console.ReadLine(), CustPhone = Convert.ToInt32(System.Console.ReadLine()), CustAddress = System.Console.ReadLine(), CustPassword = Encoding.ASCII.GetBytes(System.Console.ReadLine()), RoleId = Convert.ToInt32(System.Console.ReadLine()) }); System.Console.WriteLine("You change the: Id - " + customer.CustomerDataId + "; Name - " + customer.CustName + " " + customer.CustSurname + "; Email - " + customer.CustEmail + "; Phone - " + customer.CustPhone + "; Address - " + customer.CustAddress + "; Password - " + customer.CustPassword + "; Role Id - " + customer.RoleId); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "d": System.Console.WriteLine("Choose Id:"); dal.DeleteUser(Convert.ToInt32(System.Console.ReadLine())); System.Console.WriteLine("Delete successful"); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; default: return; } } }