private void dgvCustomer_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { String id = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[0].Value.ToString(); String name = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[1].Value.ToString(); String surname = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[2].Value.ToString(); String dni = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[3].Value.ToString(); String address = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[4].Value.ToString(); String phone = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[5].Value.ToString(); String email = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[6].Value.ToString(); String refzipcodescities = dgvCustomer.Rows[dgvCustomer.CurrentRow.Index].Cells[7].Value.ToString(); DtoCustomer dtoC = new DtoCustomer(id, name, surname, address, phone, email, refzipcodescities, dni); if (observer != null) { observer.updateCustomer(dtoC); Dispose(); } if (observerMod != null) { observerMod.updateCustomer(dtoC); Dispose(); } }
public async Task <IActionResult> UpdateCustomer([FromBody] DtoCustomer customer) { try { var result = await Task.FromResult(BL.CustomersManagement.Update(customer)); switch (result) { case BL.Responses.Unknown: case BL.Responses.Failed: default: return(BadRequest()); case BL.Responses.NoFound: return(NotFound()); case BL.Responses.NoChanges: return(StatusCode(StatusCodes.Status304NotModified)); case BL.Responses.Success: return(Ok(true)); } } catch (Exception ex) { return(BadRequest()); } }
public void updateCustomer(DtoCustomer customer) { //Console.WriteLine(customer.Name+" "+ customer.Surname); this.dtoCustomer = customer; this.idcustomer = customer.Idcustomer; txtCustomer.Text = customer.Name + " " + customer.Surname; }
/// <summary> /// Hashes password /// </summary> /// <param name="password">Unhashed password</param> /// <param name="c">Customer whose password it is</param> /// <returns>Hashed password</returns> public static string HashPassword(string password, DtoCustomer c) { SHA256 sha256 = new SHA256Managed(); var saltedPassword = GetSaltedPassword(password, c); var bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(saltedPassword)); var hash = Convert.ToBase64String(bytes); return(hash); }
public async Task <HttpResponseMessage> Create([FromBody] DtoCustomer cust) { _logger.Debug("Web api : creating customer!"); using (var custService = new CustomerService(DbContextFactory.Create())) { var entity = DaoFactory.Create <Angular2.Mvc.Core.Models.DTO.DtoCustomer, Angular2.Mvc.DAL.Models.DAO.Customer>(cust); custService.Add(entity); } return(new HttpResponseMessage(HttpStatusCode.Created)); }
public void InsertCustomer_Deadlock_Exception() { //Arrange var dtoCustomer = new DtoCustomer { CustomerCode = 32, CustomerName = "testCustomer", Id = 3 }; //Act ExecuteWithMultiThreads(ExecuteForInsert, 10, dtoCustomer); //Assert Assert.IsTrue(exceptionList.Count < 10); }
/// <summary> /// Adding or Updating Customer in a database /// </summary> /// <param name="customer">Business Object Customer</param> /// <returns>True if succeeded and false otherwise</returns> public async Task <bool> SaveCustomer(DtoCustomer customer) { try { using (var data = Context) { var c = await (from item in data.Customer where customer.Id == item.id select item).FirstOrDefaultAsync(); // Updating Customer if (c != null) { c.name = customer.Name; c.surname = customer.Surname; c.street = customer.Street; c.postalCode = customer.PostalCode; c.phoneNumber = customer.PhoneNumber; c.personalIdentityNumber = customer.PersonalIdentityNumber; c.identityCardNumber = customer.IdentityCardNumber; c.icePhoneNumber = customer.IcePhoneNumber; c.houseNumber = customer.HouseNumber; c.email = customer.Email; c.city = customer.City; c.apartmentNumber = customer.ApartmentNumber; c.password = AuthenticationLogic.HashPassword(customer.Password, customer); } // Adding new Customer else { if ( await (from item in data.Customer where customer.PersonalIdentityNumber == item.personalIdentityNumber select item).AnyAsync()) { return(false); } data.Customer.Add(CustomerConverter.DtoToDataAccess(customer)); } await data.SaveChangesAsync(); } return(true); } catch (Exception) { return(false); } }
public void HandleBezoekerMessage(BezoekerMessage bezoekerMessage) { DtoCustomer dtoCustomer = new DtoCustomer( bezoekerMessage.body.bezoekerUUID.ToString(), bezoekerMessage.body.kaartUUID.ToString(), bezoekerMessage.body.adres.ToString(), /*Voornaam en achternam*/ "Anthony Moortgat", bezoekerMessage.body.email.ToString(), /*Barcode*/ "ABC-abc-1234", bezoekerMessage.body.btwnummer.ToString(), bezoekerMessage.body.isActief, bezoekerMessage.body.isGeblokkeerd, bezoekerMessage.header.timestamp, bezoekerMessage.header.versie ); // Call API function en stuur object door throw new NotImplementedException(); }
public static Responses Update(DtoCustomer customer) { Responses result = Responses.Unknown; try { int id = customer.CustomerNumber; using (var context = new classicmodelsContext()) { Customer customerToUpdate = context.Customers.FirstOrDefault(c => c.CustomerNumber == id); if (customerToUpdate != null) { customerToUpdate.CustomerName = customer.CustomerName; customerToUpdate.ContactLastName = customer.ContactLastName; customerToUpdate.ContactFirstName = customer.ContactFirstName; customerToUpdate.Phone = customer.Phone; customerToUpdate.AddressLine1 = customer.AddressLine1; customerToUpdate.AddressLine2 = customer.AddressLine2; customerToUpdate.City = customer.City; customerToUpdate.State = customer.State; customerToUpdate.PostalCode = customer.PostalCode; customerToUpdate.Country = customer.Country; customerToUpdate.CreditLimit = customer.CreditLimit; customerToUpdate.SalesRepEmployeeNumber = customer.SalesRepEmployeeNumber; result = context.SaveChanges() > 0 ? Responses.Success : Responses.NoChanges; } else { result = Responses.NoFound; } } } catch (Exception ex) { result = Responses.Failed; } return(result); }
/// <summary> /// dto to Data Access Conversion /// </summary> /// <param name="customer">dto Customer</param> /// <returns>Data Access Customer</returns> public static Customer DtoToDataAccess(DtoCustomer customer) { return(new Customer { id = customer.Id, name = customer.Name, surname = customer.Surname, email = customer.Email, phoneNumber = customer.PhoneNumber, icePhoneNumber = customer.IcePhoneNumber, personalIdentityNumber = customer.PersonalIdentityNumber, identityCardNumber = customer.IdentityCardNumber, city = customer.City, street = customer.Street, postalCode = customer.PostalCode, houseNumber = customer.HouseNumber, apartmentNumber = customer.ApartmentNumber, password = AuthenticationLogic.HashPassword(customer.Password, customer) }); }
/// <summary> /// DTO to Viem Model Conversion /// </summary> /// <param name="customer">DTO Customer</param> /// <returns>View Model Customer</returns> public static Customer DtoToViewModel(DtoCustomer customer) { return(new Customer { Id = customer.Id, Name = customer.Name, Surname = customer.Surname, Email = customer.Email, PhoneNumber = customer.PhoneNumber, IcePhoneNumber = customer.IcePhoneNumber, PersonalIdentityNumber = customer.PersonalIdentityNumber, IdentityCardNumber = customer.IdentityCardNumber, City = customer.City, Street = customer.Street, PostalCode = customer.PostalCode, HouseNumber = customer.HouseNumber, ApartmentNumber = customer.ApartmentNumber, Password = customer.Password }); }
public bool InsertCustomer(DtoCustomer customer, int num) { var sqlConnection = new SqlConnection(@"Data Source=.;Initial Catalog=DeadlockTests;Integrated Security=True"); sqlConnection.Open(); var transaction = sqlConnection.BeginTransaction(); Shared.UnityConfiguration.Container.Resolve <IUnitOfWork>().Transaction = transaction; using (var objCommand = new SqlCommand()) { objCommand.Connection = sqlConnection; objCommand.Transaction = transaction; objCommand.CommandText = "DEADLOCKPROC"; objCommand.CommandType = CommandType.StoredProcedure; objCommand.Parameters.AddWithValue("COLNUM", num); objCommand.CommandTimeout = 60; objCommand.ExecuteNonQuery(); } return(true); }
public async Task <HttpResponseMessage> Update([FromBody] DtoCustomer cust) { using (var custService = new CustomerService(DbContextFactory.Create())) { var entity = custService.Get(x => x.Id.Equals(cust.Id)).FirstOrDefault(); if (entity != null) { entity.Name = cust.Name; entity.Age = cust.Age; entity.Phone = cust.Phone; entity.Description = cust.Description; custService.Update(entity); } else { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } } return(new HttpResponseMessage(HttpStatusCode.OK)); }
public async Task <ActionResult> EditData() { DtoCustomer model = await new CustomerLogic().GetCustomer(System.Web.HttpContext.Current.User.Identity.Name); return(View(new EditDataViewModel { Id = model.Id, Name = model.Name, Surname = model.Surname, Street = model.Street, City = model.City, PostalCode = model.PostalCode, PhoneNumber = model.PhoneNumber, IcePhoneNumber = model.IcePhoneNumber, Email = model.Email, IdentityCardNumber = model.IdentityCardNumber, PersonalIdentityNumber = model.PersonalIdentityNumber, ApartmentNumber = model.ApartmentNumber, HouseNumber = model.HouseNumber })); }
private async Task <bool> UpdateCustomer(DtoCustomer customer) { bool result = false; using (var httpClient = new System.Net.Http.HttpClient()) { httpClient.BaseAddress = new Uri(URL); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await Task.FromResult(httpClient.PutAsJsonAsync("api/customer", customer).Result); response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { result = await response.Content.ReadAsAsync <bool>(); } } return(result); }
public Thread ExecuteForInsert(DtoCustomer customer, int threadNum) { var thread = new Thread(() => { try { new BoCustomer().Insert(customer, threadNum); } catch (Exception ex) { var sqlException = ex as SqlException; if (sqlException != null && sqlException.Number == 1205) { Console.WriteLine($"Deadlock on thread #{threadNum}"); exceptionList.Add(sqlException); } } }); thread.Start(); return(thread); }
/// <summary> /// Save data /// </summary> /// <param name="model">Model</param> /// <returns>Save data view</returns> public async Task <ActionResult> SaveData(EditDataViewModel model) { DtoCustomer customer = new DtoCustomer() { Id = model.Id, Name = model.Name, Surname = model.Surname, Street = model.Street, City = model.City, PostalCode = model.PostalCode, PhoneNumber = model.PhoneNumber, IcePhoneNumber = model.IcePhoneNumber, Email = model.Email, IdentityCardNumber = model.IdentityCardNumber, PersonalIdentityNumber = model.PersonalIdentityNumber, ApartmentNumber = model.ApartmentNumber, HouseNumber = model.HouseNumber, Password = model.Password }; CustomerLogic logic = new CustomerLogic(); bool isRegistrationSuccessful = await logic.SaveCustomer(customer); string errorText = null; if (isRegistrationSuccessful) { FormsAuthentication.RedirectFromLoginPage(model.Email, true); } else { errorText = "Błąd podczas zapisywania danych"; } return(View("EditData", new EditDataViewModel() { ErrorText = errorText })); }
public void ExecuteWithMultiThreads(Func <DtoCustomer, int, Thread> action, int threadsNum, DtoCustomer customer) { var threadList = new List <Thread>(); for (var i = 0; i < threadsNum; i++) { threadList.Add(action.Invoke(customer, i)); } while (threadList.Any(thread => thread.IsAlive)) { } }
private static string GetSaltedPassword(string password, DtoCustomer c) { return(c.Email + password); }
public void Update(DtoCustomer customer) { customer.CustomerCode = new Random().Next(0, 500); _customerRepository.UpdateCustomer(customer); }
public void Insert(DtoCustomer customer, int num) { _uow.Commit(() => _customerRepository.InsertCustomer(customer, num)); }
public virtual bool UpdateCustomer(DtoCustomer customer) { throw new NotImplementedException(); }