コード例 #1
0
        public async Task <IActionResult> Edit([FromServices] IHostingEnvironment env, ValueMaps model)
        {
            ValueMaps updated = new ValueMaps();

            if (ModelState.IsValid)
            {
                var auth = await HttpContext.AuthenticateAsync();

                string currentUser = "";
                string currentip   = ContextIP.GetUserIp(this.HttpContext);
                if (auth.Succeeded)
                {
                    currentUser = auth.Principal.Identity.Name;
                }
                updated = await valuemapsRepository.GetByIdAsync(model.Id);

                updated.SystemId          = model.SystemId;
                updated.Threshold         = model.Threshold;
                updated.ValuationFunction = model.ValuationFunction;
                updated.Uid           = currentUser;
                updated.TransdateTime = DateTime.Now;
                var mapping = systemRepository.FindById(model.SystemId);
                updated.System = mapping;


                await valuemapsRepository.UpdateAsync(updated);
            }
            else
            {
                return(BadRequest("Something is wrong,please retry"));
            }
            //if (!note.Password.Equals(password))

            return(View("Details", updated));
        }
コード例 #2
0
        public async Task <IActionResult> Add([FromServices] IHostingEnvironment env, ValueMapsModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var auth = await HttpContext.AuthenticateAsync();

            string currentUser = "";
            string currentip   = ContextIP.GetUserIp(this.HttpContext);

            if (auth.Succeeded)
            {
                currentUser = auth.Principal.Identity.Name;
            }


            string    filename = string.Empty;
            ValueMaps tempin   = new ValueMaps
            {
                SystemId          = model.System,
                ValuationFunction = model.ValuationFunction,
                TransdateTime     = DateTime.Now,
                Threshold         = model.Threshold,
                Uid = currentUser
            };
            await valuemapsRepository.AddAsync(tempin);

            //redis
            await _redisService.SetAsync("First", tempin.ToString());



            StringBuilder sb = new StringBuilder();

            sb.Append("<table class='table' style='border: solid; color: silver'>"
                      + "<thead style='border: solid; color: red'>" + "< tr>< th > User </ th >< th > Datatime </ th ></ tr ></thead>" +
                      "<tbody style='border: solid; color: goldenrod'>"
                      + "<tr>< td >" + currentUser + " </ td >< td >" + DateTime.Now + " </ td ></ tr >< tr > "

                      + "</table>");
            sb.AppendLine(tempin.SetJSONString());
            //byte[] tempssin = tempin.SetBinary<ValueMaps>();
            //AddRedisData(tempssin);

            //pubish redis message
            //using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379"))
            //{
            //    ISubscriber sub = redis.GetSubscriber();
            //  var rel=  sub.Publish("Addmessages", tempin.SetJSONString());
            //}


            //var busConfig = new RawRabbitConfiguration
            //rabbitmq
            //= new RabbitMqOptions
            //{
            //    Username = "******",
            //    Password = "******",
            //    Port = 5672,
            //    VirtualHost = "/",
            //    Hostnames = { "localhost" }

            //};
            //var busClient = BusClientFactory.CreateDefault(rabbitmq);
            busClient = BusClientFactory.CreateDefault(new RabbitMqOptions());
            //using (var busClient = BusClientFactory.CreateDefault(new RabbitMqOptions()))
            //{
            await busClient.PublishAsync <string>(tempin.SetJSONString());

            //}


            //await  emailSender.SendEmailAsync(currentUser, "Added one record!", sb.ToString());
            //await  valuemapsRepository.PublishAsync(tempin);
            return(RedirectToAction("Index"));
        }