public ActionResult Create(MappingTag mappingtag, FormCollection form)
        {
            ViewData["ValidationErrorMessage"] = String.Empty;
            if (this.FormCollectionIsValid(form))
            {
                mappingtag.Appliance = dbA.GetById(Convert.ToInt32(form["ApplianceId"]));
                mappingtag.Signal = dbS.GetById(Convert.ToInt32(form["SignalId"]));
                mappingtag.AlarmType = dbAT.GetById(Convert.ToInt32(form["AlarmTypeId"]));
                db.Save(this.RemoveExtraSpaces(mappingtag));

                List<Object> logList = new List<Object>();
                logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["CreateText"] +
                                          ControllerContext.RouteData.Values["controller"] +
                                          "(Id=" + mappingtag.Id.ToString().Replace("-", "").ToUpper() +
                                          " - Description=" + mappingtag.Description +
                                          " - Tag=" + mappingtag.Tag +
                                          " - AlarmTypeName=" + mappingtag.AlarmType.NameAlarmType +
                                          " - ApplianceName=" + mappingtag.Appliance.NameAppliance +
                                          " - SignalName=" + mappingtag.Signal.Name + ")",
                                          (int)EventTypes.Create,
                                          (int)Session["UserId"]));
                log.Write(logList);

                return RedirectToAction("Index");
            }

            ViewBag.ApplianceId = !String.IsNullOrEmpty(form["ApplianceId"]) ? new SelectList(dbA.GetAll(), "Id", "NameAppliance", form["ApplianceId"]) : new SelectList(dbA.GetAll(), "Id", "NameAppliance");
            ViewBag.SignalId = !String.IsNullOrEmpty(form["SignalId"]) ? new SelectList(dbS.GetAll(), "Id", "Name", form["SignalId"]) : new SelectList(dbS.GetAll(), "Id", "Name");
            ViewBag.AlarmTypeId = !String.IsNullOrEmpty(form["AlarmTypeId"]) ? new SelectList(dbAT.GetAll(), "Id", "NameAlarmType", form["AlarmTypeId"]) : new SelectList(dbAT.GetAll(), "Id", "NameAlarmType");

            return View(mappingtag);
        }
Example #2
0
        public void TestMethod1()
        {
            IRepository<Monitoring> repoM = new MonitoringRepository();
            var res = repoM.GetByProperty("CommentsOnAlarm", null);

            IRepository<Signal> repo1 = new SignalRepository();
            Signal signal = new Signal();
            signal = repo1.GetById(1);
            IRepository<Appliance> repo2 = new ApplianceRepository();
            Appliance appliance = new Appliance();
            appliance = repo2.GetById(1);
            IRepository<AlarmType> repo3 = new AlarmTypeRepository();
            AlarmType alarmType = new AlarmType();
            alarmType = repo3.GetById(1);
            IRepository<User> repo4 = new UserRepository();
            User user = new User();
            user = repo4.GetById(2);

            IRepository<MappingTag> repoMT = new MappingTagRepository();
            MappingTag tag = new MappingTag();
            tag.Tag = "PruebaTag";
            tag.Description = "Prueba descriptiva mapping tag";
            tag.Signal = signal;
            tag.Appliance = appliance;
            tag.AlarmType = alarmType;

            Monitoring monitor = new Monitoring();
            monitor.Value = float.Parse("2.400");
            monitor.DateTime = DateTime.Now;
            monitor.CommentsOnAlarm = "Prueba de comentarios sobre alarma, monitoreo";
            monitor.MappingTag = tag;
            monitor.User = user;

            tag.Monitorings.Add(monitor);

            repoMT.Save(tag);

            /*INSERT 4000 RECORDS for TEST*/
            //IRepository<Monitoring> repoM = new MonitoringRepository();
            //IRepository<User> repo4 = new UserRepository();
            //User user = new User();
            //user = repo4.GetById(6);

            //IRepository<MappingTag> repoMT = new MappingTagRepository();
            //MappingTag tag = new MappingTag();
            //tag = repoMT.GetById(103);

            //for (int i = 0; i < 4000; i++)
            //{
            //    Monitoring monitor = new Monitoring();
            //    monitor.Value = (1000 + i);
            //    monitor.DateTime = DateTime.Now;
            //    monitor.CommentsOnAlarm = null;
            //    monitor.MappingTag = tag;
            //    monitor.User = user;

            //    repoM.Save(monitor);
            //}
        }
        private MappingTag RemoveExtraSpaces(MappingTag mappingtag)
        {
            mappingtag.Tag = !String.IsNullOrWhiteSpace(mappingtag.Tag) ? mappingtag.Tag.Trim() : null;
            mappingtag.Description = !String.IsNullOrWhiteSpace(mappingtag.Description) ? mappingtag.Description.Trim() : null;

            return mappingtag;
        }