Esempio n. 1
0
        //GET
        //Retrieves existing customer from the database Author Stephen Sander
        public ActionResult GetCustomer(string username)
        {
            username = (string)Session["Username"];
            UpdateCustomer oldCust = CustomersDB.GetCustomer(username);

            return(View(oldCust));
        }
Esempio n. 2
0
        public async Task <RequestResult> UpdateAsync(UpdateCustomer updateCustomer, CancellationToken cancellationToken)
        {
            var customer = new Customer {
                Id = updateCustomer.Id, Name = updateCustomer.Name.Trim(), Age = updateCustomer.Age
            };

            var result = new RequestResult {
                IsSuccess = false, Errors = customer.Validate()
            };

            if (result.Errors.Count() < 1)
            {
                var register = await _customerRepository.UpdateAsync(customer, cancellationToken);

                if (register > 0)
                {
                    result.IsSuccess = true;
                    return(result);
                }

                result.Errors = new List <string> {
                    "Erro on update Customer."
                };
            }

            return(result);
        }
        private void BtnUpdateCustomer_Click(object sender, EventArgs e)
        {
            UpdateCustomer updateCustomer = new UpdateCustomer();

            this.Hide();
            updateCustomer.Show();
        }
Esempio n. 4
0
        public ActionResult GetCustomer(UpdateCustomer newCust)
        {
            string username = (string)Session["Username"];

            try
            {
                UpdateCustomer oldCust = CustomersDB.GetCustomer(username);
                //Thread.Sleep(10000)
                int count = CustomersDB.UpdateCustomer(oldCust, newCust);
                if (count == 0)// no update due to concurrency issue
                {
                    TempData["errorMessage"] = "Update aborted. " +
                                               "Another user changed or deleted this row";
                }
                else
                {
                    TempData["errorMessage"] = "";
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 5
0
 private void CustomerActivity(object obj)
 {
     switch (obj as string)
     {
     case "UpdateCustomer":
     {
         if (updateCustomerWindow == null)
         {
             updateCustomerWindow = new UpdateCustomer
             {
                 DataContext = new UpdateCustomerVM()
             };
             updateCustomerWindow.Show();
         }
         else
         {
             if (updateCustomerWindow.IsLoaded.Equals(false))
             {
                 updateCustomerWindow = null;
                 updateCustomerWindow = new UpdateCustomer
                 {
                     DataContext = new UpdateCustomerVM()
                 };
                 updateCustomerWindow.Show();
             }
             else
             {
                 updateCustomerWindow.Focus();
             }
         }
     }
     break;
     }
 }
 public DefaultScope()
 {
     CustomerRepositoryMock = new Mock <ICustomerRepository>();
     IdentityResolverMock   = new Mock <IIdentityResolver>();
     IdentityResolverMock.Setup(x => x.GetUserNameAsync()).ReturnsAsync(UserName);
     InstanceUnderTest = new UpdateCustomer(CustomerRepositoryMock.Object, IdentityResolverMock.Object);
 }
        public static void OpenUpdateCustomerForm(Dictionary <string, Label> customerValueLabels, PictureBox pictureBox,
                                                  RichTextBox commentsRichTextBox, BindingNavigator bindingNavigatorCustomers)
        {
            UpdateCustomer form = new UpdateCustomer(customerValueLabels, pictureBox, commentsRichTextBox, bindingNavigatorCustomers);

            form.Show();
        }
Esempio n. 8
0
        /// <summary>
        /// Update customer data
        /// </summary>
        /// <param name="handle">Customer id, blank for auto generate</param>
        /// <param name="email"> customer email</param>
        /// <param name="firstName">custoemer firstname</param>
        /// <param name="lastname">customer last name</param>
        /// <param name="address">customer address</param>
        /// <param name="address2">customer address2</param>
        /// <param name="city">customer city</param>
        /// <param name="postalCode">customer postal code</param>
        /// <param name="country">customer country</param>
        /// <param name="phone">customer phone</param>
        /// <param name="company">customer company</param>
        /// <param name="vat">customer vat</param>
        /// <returns>statuscode and customer data</returns>
        public ApiResponse <Customer> UpdateCustomer(string handle, string email, string firstName, string lastname, string address, string address2, string city,
                                                     string postalCode, string country, string phone, string company, string vat)
        {
            var myClassname = MethodBase.GetCurrentMethod().Name;
            var config      = this.GetDefaultApiConfiguration();
            var api         = new CustomerApi(config);
            var customer    = new UpdateCustomer(email, address, address2, city, country, phone, company, vat, firstName, lastname, postalCode);

            for (var i = 0; i <= MaxNoOfRetries; i++)
            {
                try
                {
                    var apiResponse = api.UpdateCustomerJsonWithHttpInfo(handle, customer);
                    return(apiResponse);
                }
                catch (ApiException apiException)
                {
                    this._log.Error($"{myClassname} {apiException.ErrorCode} {apiException.ErrorContent}");
                    return(new ApiResponse <Customer>(apiException.ErrorCode, null, null));
                }
                catch (Exception) when(i < MaxNoOfRetries)
                {
                    this._log.Debug($"{myClassname} retry attempt {i}");
                }
            }

            return(new ApiResponse <Customer>((int)HttpStatusCode.InternalServerError, null, null));
        }
Esempio n. 9
0
        // GET: People/Edit/5
        public async Task <IActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var customer = await this.GetCustomerDetail(id.Value);

            if (customer == null)
            {
                return(NotFound());
            }

            var updateCustomer = new UpdateCustomer()
            {
                Id        = id.Value,
                FirstName = customer.FirstName,
                LastName  = customer.LastName,
                Email     = customer.Email,
                Phone     = customer.Phone
            };

            return(View(updateCustomer));
        }
        public void should_call_UpdateCustomer()
        {
            //arrange
            var customerId = CreateCustomer();

            var request = new UpdateCustomer
            {
                Company      = "Test API Company, LLC",
                BillAddr1    = "220 ChargeOver Street",
                BillAddr2    = "Suite 10",
                BillCity     = "Minneapolis",
                BillState    = "MN",
                BillPostcode = "55416",
                BillCountry  = "USA"
            };
            //act
            var actual = Sut.UpdateCustomer(customerId, request);

            //assert
            Assert.AreEqual(202, actual.Code);
            Assert.IsEmpty(actual.Message);
            Assert.AreEqual("OK", actual.Status);
            var customer = Sut.QueryForCustomers(new[] { "customer_id:EQUALS:" + customerId }).Response.First();

            Assert.AreEqual(request.BillAddr1, customer.BillAddr1);
        }
 public CustomerViewModel()
 {
     addCustomer     = new AddCustomer(this);
     deleteCustomer  = new DeleteCustomer(this);
     updateCustomer  = new UpdateCustomer(this);
     SelectCustomer  = new CustomerEntity();
     CurrentCustomer = new CustomerEntity();
 }
        public Task Handle(object Command)
        {
            return(Command switch
            {
                AddCustomer cmd => HandleCreate(cmd),
                UpdateCustomer cmd => HandleUpdate(cmd.Id, c => c.BusinessCustomerUpdate(cmd.CompanyId, cmd.FirstName, cmd.LastName, cmd.CVR, cmd.EAN, cmd.WWW, cmd.VatCode, cmd.DebitorNo, cmd.Username, cmd.Password, cmd.Text, cmd.AccountNo, cmd.LastUpdate)),
                DeleteCustomer cmd => HandleDelete(cmd.Id),

                _ => Task.CompletedTask
            });
Esempio n. 13
0
 public static Customer MapToCustomer(this UpdateCustomer command) => new Customer
 {
     CustomerId      = command.CustomerId,
     Name            = command.Name,
     Address         = command.Address,
     PostalCode      = command.PostalCode,
     City            = command.City,
     TelephoneNumber = command.TelephoneNumber,
     EmailAddress    = command.EmailAddress
 };
        public Task Handle(object Command)
        {
            return(Command switch
            {
                AddCustomer cmd => HandleCreate(cmd),
                UpdateCustomer cmd => HandleUpdate(cmd.Id, c => c.PrivateCustomerUpdate(cmd.CompanyId, cmd.FirstName, cmd.LastName, cmd.Username, cmd.Password, cmd.Text, cmd.AccountNo, cmd.LastUpdate)),
                DeleteCustomer cmd => HandleDelete(cmd.Id),

                _ => Task.CompletedTask
            });
Esempio n. 15
0
        public AdminDashboardViewModel UpdateCustomers(string CustomerID, string CustomerName, string Address, string PhoneNumber, string Password, string EmailAddress, string Status)
        {
            CustomerUpdate          Reposi    = new CustomerUpdate();
            AdminDashboardViewModel viewModel = new AdminDashboardViewModel();
            UpdateCustomer          model     = new UpdateCustomer();

            model = Reposi.UpdateCustomerList(CustomerID, CustomerName, Address, PhoneNumber, Password, EmailAddress, Status);
            viewModel.CustomerListUpdate = model;
            return(viewModel);
        }
Esempio n. 16
0
        public object Put(UpdateCustomer request)
        {
            var entity = request.ConvertTo <Customer>();

            return(InTransaction(db =>
            {
                Logic.Update(entity);
                return new CommonResponse(Logic.GetById(entity.Id));
            }));
        }
Esempio n. 17
0
        public async Task <IActionResult> UpdateAsync([FromRoute] string customerId, [FromBody] UpdateCustomer command)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var existingCustomer = await _dbContext.Customers
                                           .FirstOrDefaultAsync(o => o.CustomerId == customerId);

                    if (existingCustomer == null)
                    {
                        return(NotFound());
                    }

                    existingCustomer.CustomerId      = command.CustomerId;
                    existingCustomer.Address         = command.Address;
                    existingCustomer.City            = command.City;
                    existingCustomer.EmailAddress    = command.EmailAddress;
                    existingCustomer.Name            = command.Name;
                    existingCustomer.PostalCode      = command.PostalCode;
                    existingCustomer.TelephoneNumber = command.TelephoneNumber;

                    try
                    {
                        _dbContext.Customers.Update(existingCustomer);
                    }
                    catch (Exception)
                    {
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists " +
                                                 "see your system administrator.");
                        return(StatusCode(StatusCodes.Status500InternalServerError));

                        throw;
                    }

                    await _dbContext.SaveChangesAsync();

                    var e = command.MapToCustomerUpdated();
                    await _messagePublisher.PublishMessageAsync(e.MessageType, e, "");

                    return(Ok());
                }
                return(BadRequest());
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
                return(StatusCode(StatusCodes.Status500InternalServerError));

                throw;
            }
        }
Esempio n. 18
0
 public static CustomerUpdated MapToCustomerUpdated(this UpdateCustomer command) => new CustomerUpdated
 (
     System.Guid.NewGuid(),
     command.CustomerId,
     command.Name,
     command.Address,
     command.PostalCode,
     command.City,
     command.TelephoneNumber,
     command.EmailAddress
 );
Esempio n. 19
0
 public object Put(UpdateCustomer request)
 {
     var customer = this.Db.LoadSingleById<Customer>(request.Id);
     customer = customer.PopulateWith(request.ConvertTo<Customer>());
     this.Db.Update(customer);
     //Invalidate customer details cache
     this.Cache.ClearCaches(CacheKey.Fmt(request.Id));
     return new UpdateCustomerResponse()
     {
         Result = customer
     };
 }
Esempio n. 20
0
        public Customer UpdateCustomer(UpdateCustomer customer)
        {
            // Implement business logic

            return(new Customer(
                       customer.CustomerReference,
                       customer.FirstName,
                       customer.Surname,
                       customer.Status,
                       customer.CreatedDate,
                       DateTime.UtcNow));
        }
Esempio n. 21
0
    public object Put(UpdateCustomer request)
    {
        var customer = Db.SingleById <Customer>(request.Id);

        if (customer == null)
        {
            throw HttpError.NotFound("Customer '{0}' does not exist".Fmt(request.Id));
        }
        customer.Name = request.Name;
        Db.Update(customer);
        return(customer);
    }
Esempio n. 22
0
        public async Task CustomerUpdateFailByCustomerNameNotIsFullName()
        {
            var customerService = new CustomerService(_customerRepository.Object);

            var updateCustomer = new UpdateCustomer {
                Age = 18, Name = "Cesar"
            };

            var result = await customerService.UpdateAsync(updateCustomer, It.IsAny <CancellationToken>());

            Assert.False(result.IsSuccess);
            Assert.Contains("Customer need it full name.", result.Errors);
        }
Esempio n. 23
0
        public object Put(UpdateCustomer request)
        {
            var customer = this.Db.LoadSingleById <Customer>(request.Id);

            customer = customer.PopulateWith(request.ConvertTo <Customer>());
            this.Db.Update(customer);
            //Invalidate customer details cache
            this.Cache.ClearCaches(CacheKey.Fmt(request.Id));
            return(new UpdateCustomerResponse()
            {
                Result = customer
            });
        }
Esempio n. 24
0
        public object Put(UpdateCustomer request)
        {
            var customer = documentSession.Load<Customer>(request.Id);
            if (customer == null)
                HttpError.NotFound("Customer not found!");

            customer.PopulateWith(request);

            documentSession.Store(customer);
            documentSession.SaveChanges();

            return customer;
        }
Esempio n. 25
0
        public async Task <IActionResult> UpdateCustomerAsync(
            [FromRoute] int id,
            [FromBody] UpdateCustomer command,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }
            await Mediator.Send(command, cancellationToken).ConfigureAwait(false);

            return(NoContent());
        }
        public void Handle(UpdateCustomer command)
        {
            ValidateCommand(command);
            var exists = _context.Exists(
                $"(\"EmailAddress\" = '{command.Email}') AND (\"Id\" <> '{command.Id}')", "Customers");

            var lastCommand = GetLastCommand(command.Id);

            UpdateCustomer(command);

            command.AggregateId = command.Id;
            AddEventSourcing(command, "Updated Customer", lastCommand);
        }
Esempio n. 27
0
        public async Task CustomerUpdateFailByCustomerUnder18()
        {
            var customerService = new CustomerService(_customerRepository.Object);

            var updateCustomer = new UpdateCustomer {
                Age = 10, Name = "Cesar Brito"
            };

            var result = await customerService.UpdateAsync(updateCustomer, It.IsAny <CancellationToken>());

            Assert.False(result.IsSuccess);
            Assert.Contains("Customer can't age under 18.", result.Errors);
        }
 /// <summary>
 /// Update Customer Operation
 /// </summary>
 private void UpdateMethod()
 {
     if (null != selectedcustomer)
     {
         //Displays the Update Window
         UpdateCustomer update = new UpdateCustomer(selectedcustomer);
         update.Show();
     }
     else
     {
         MessageBox.Show("Please search for a customer before you" + "attempt to delete.", "No selected customer");
     }
 }
Esempio n. 29
0
        public async Task CustomerUpdateFailByCustomerNameLengthBelow3()
        {
            var customerService = new CustomerService(_customerRepository.Object);

            var updateCustomer = new UpdateCustomer {
                Age = 18, Name = "Ce"
            };

            var result = await customerService.UpdateAsync(updateCustomer, It.IsAny <CancellationToken>());

            Assert.False(result.IsSuccess);
            Assert.Contains("Customer name can't length under 3 characters.", result.Errors);
        }
Esempio n. 30
0
        public UpdateCustomerResponse Put(UpdateCustomer request)
        {
            var customer = Db.SingleById<Customer>(request.Id);
            if (customer == null)
                throw HttpError.NotFound("Customer '{0}' does not exist".Fmt(request.Id));

            customer.Name = request.Name;
            Db.Update(customer);

            return new UpdateCustomerResponse
            {
                Result = customer
            };
        }
Esempio n. 31
0
        public async Task CustomerUpdateFailByCantUpdateCustomer()
        {
            _customerRepository.Setup(i => i.UpdateAsync(It.IsAny <Customer>(), It.IsAny <CancellationToken>())).ReturnsAsync(0);

            var customerService = new CustomerService(_customerRepository.Object);

            var updateCustomer = new UpdateCustomer {
                Age = 18, Name = "Cesar brito"
            };

            var result = await customerService.UpdateAsync(updateCustomer, It.IsAny <CancellationToken>());

            Assert.False(result.IsSuccess);
            Assert.Contains("Erro on update Customer.", result.Errors);
        }
        private void UpdateAddress(UpdateCustomer command)
        {
            var idAddress = GetIdAddress(command.Id);
            var sb        = new StringBuilder()
                            .AppendLine($"UPDATE \"Addresses\" SET " +
                                        $"\"Number\" = '{command.Number}', " +
                                        $"\"Street\" = '{command.Street}', " +
                                        $"\"City\" = '{command.City}', " +
                                        $"\"ZipCode\" = '{command.ZipCode}' ")
                            .AppendLine($"WHERE \"Id\" = '{idAddress}';")
                            .AppendLine("SELECT changes();");
            var sql = sb.ToString();

            _context.Connection.Execute(sql);
        }
        public void UpdateCustomer(UpdateCustomer command)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"UPDATE \"Customers\" SET ");
            sb.AppendLine($" \"FirstName\" = '{command.FirstName}', ");
            sb.AppendLine($" \"EmailAddress\" = '{command.Email}', ");
            sb.AppendLine($" \"BirthDate\" = '{command.BirthDate}', ");
            sb.AppendLine($" \"Score\" = '{command.Score}' ");
            sb.AppendLine($"WHERE \"Id\" = '{command.Id}';");
            var sql = sb.ToString();

            UpdateAddress(command);
            _context.Connection.Execute(sql);
        }
Esempio n. 34
0
        public object Delete(UpdateCustomer request)
        {
            var customer = documentSession.Load<Customer>(request.Id);
            if (customer == null)
                HttpError.NotFound("Customer not found!");

            documentSession.Delete(customer);
            documentSession.SaveChanges();

            return
                new HttpResult
                    {
                        StatusCode = HttpStatusCode.NoContent,
                    };
        }