private void UpdateBtn_Click(object sender, EventArgs e) { Customer customer = new Customer(); getDate(customer); if (UpdateBtn.Text == "Add Customer") { bool flag = controller.Insert(customer); if (flag) { flag2 = flag; MessageBox.Show(null, "Customer inserted successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(null, "Please check your input", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { customer.ID = id; bool flag = controller.Update(customer); if (flag) { flag2 = flag; MessageBox.Show(null, "Customer updated successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(null, "Please check your input", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void ProcessRequest(HttpContext context) { try { var files = context.Request.Files; var delivery = JsonConvert.DeserializeObject <Delivery>(context.Request.Form["Delivery"]); var uploadPath = "/uploads/deliveries/"; if (!String.IsNullOrEmpty(delivery.Image)) { // Delete invoice image after upload image new File.Delete(context.Server.MapPath(delivery.Image)); } if (files.Count > 0) { // Trường hợp upload image new var filePathNew = String.Format( "{0}{1}-{2:yyyyMMddHHmmss}{3}", uploadPath, delivery.OrderID, DateTime.UtcNow, System.IO.Path.GetExtension(files["ImageNew"].FileName) ); files["ImageNew"].SaveAs(context.Server.MapPath(filePathNew)); delivery.Image = filePathNew; } else { // Trường hợp là remove image củ delivery.Image = String.Empty; } string username = context.Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); // Update transfer infor delivery.UUID = Guid.NewGuid(); delivery.CreatedBy = acc.ID; delivery.CreatedDate = DateTime.Now; delivery.ModifiedBy = acc.ID; delivery.ModifiedDate = DateTime.Now; DeliveryController.Update(delivery); var session = new List <DeliverySession>() { new DeliverySession() { OrderID = delivery.OrderID, ShipperID = delivery.ShipperID, CreatedDate = delivery.CreatedDate, DeliveryTimes = delivery.Times.Value, DeliveryStatus = delivery.Status, COD = delivery.COO, ShippingFee = delivery.COD } }; SessionController.updateDeliverySession(acc, session); context.Response.Write(delivery.Image); } catch (Exception ex) { context.Response.StatusCode = 400; context.Response.Write(ex.Message); } }
public async Task Three_events_send_as_two_messages() { //Настройка IOC контейнера var services = new ServiceCollection(); var config = new ConfigurationBuilder().AddJsonFile("testProject.json").Build(); var startup = new Startup(config); startup.ConfigNotificationProcessor(services); services.AddSingleton <INotificationSender, SenderMock>(sprovider => new SenderMock(2)); var serviceProvider = services.AddEntityFrameworkInMemoryDatabase().BuildServiceProvider(); //In memory dbcontext services.AddDbContext <ESHContext>(options => { options.UseInMemoryDatabase("InMemoryDbForTesting"); options.UseInternalServiceProvider(serviceProvider); }); services.AddScoped <IESHRepository, ESHRepository.EF.ESHRepository>(); var sp = services.BuildServiceProvider(); //получаем наш синглтон сендера var senderMock = (SenderMock)sp.GetService <INotificationSender>(); //моделируем работу с поставками using (var scope = sp.CreateScope()) { var repository = scope.ServiceProvider.GetRequiredService <IESHRepository>(); var notificator = scope.ServiceProvider.GetRequiredService <ConcurrentDictNotificator <SupplyOperation> >(); DeliveryController deliveryController = new DeliveryController(repository, notificator); await deliveryController.Create(new ESHRepository.Model.Supply() { Id = "1", Count = 1 }); await deliveryController.Create(new ESHRepository.Model.Supply() { Id = "2", Count = 1 }); } using (var scope = sp.CreateScope()) { var repository = scope.ServiceProvider.GetRequiredService <IESHRepository>(); var notificator = scope.ServiceProvider.GetRequiredService <ConcurrentDictNotificator <SupplyOperation> >(); DeliveryController deliveryController = new DeliveryController(repository, notificator); await deliveryController.Update(new ESHRepository.Model.Supply() { Id = "2", Count = 1 }); //ждем получения сообщений var messages = await senderMock.GetMessagesAsync().WithTimeout(10000); Assert.Equal(2, messages.Count()); Assert.True(messages.FirstOrDefault(m => m.Title.Contains("Информация по записи 2") && m.Body.Contains("Запись создана и обновлена")) != null); Assert.True(messages.FirstOrDefault(m => m.Title.Contains("Информация по записи 1") && m.Body.Contains("Запись создана")) != null); } }