Beispiel #1
0
        public void CanCreateAlarmTypeAndLog()
        {
            IRepository<AlarmType> repoA = new AlarmTypeRepository();
            AlarmType alarm = new AlarmType();
            alarm.NameAlarmType = "PruebaAlarma";
            alarm.Description = "Prueba descriptiva alarma";

            repoA.Save(alarm);

            IRepository<User> repoB = new UserRepository();
            User user = new User();
            user = repoB.GetById(1);
            IRepository<Event> repoC = new EventRepository();
            Event eventt = new Event();
            eventt = repoC.GetById(2);

            IRepository<Log> repoD = new LogRepository();
            Log log = new Log();
            log.DateTime = DateTime.Now;
            log.Text = "Prueba descriptiva log";
            log.Event = eventt;
            log.User = user;

            repoD.Save(log);
        }
Beispiel #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);
            //}
        }
Beispiel #3
0
        public ActionResult Create(User user, FormCollection form)
        {
            ViewData["ValidationErrorMessage"] = String.Empty;

            try
            {
                if (this.FormCollectionToCreateIsValid(user, form))
                {
                    user.Password = new Cryptography().EncryptSHA1(form["passwordPwd"]);
                    user.PassphraseId = int.Parse(form["PassphraseId"]);
                    user.PassphraseValue = new Cryptography().EncryptSHA1(form["passphraseValue"]);

                    db.Save(this.RemoveExtraSpaces(user));

                    List<Object> logList = new List<Object>();
                    logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["CreateText"] + ControllerContext.RouteData.Values["controller"] + "(Id=" + user.Id.ToString().Replace("-", "").ToUpper() + " - DocumentId=" + user.DocumentId + " - LoginEmail=" + user.LoginEmail + " - FirstName=" + user.FirstName + " - MiddleName=" + user.MiddleName + " - LastName1=" + user.LastName1 + " - LastName2=" + user.LastName2 + " - PhoneNumber=" + user.PhoneNumber + ")", (int)EventTypes.Create, (int)Session["UserId"]));
                    log.Write(logList);

                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            Passphrase passphrase;
            var passphrases = this.GetPassphrases();
            IList<Passphrase> listPassphrases = new List<Passphrase>();
            foreach (var item in passphrases)
            {
                passphrase = new Passphrase();
                passphrase.id = int.Parse(item.Substring(0, 1));
                passphrase.value = item.Substring(1).Trim();
                listPassphrases.Add(passphrase);
            }
            MultiSelectList mslPassphrases = new MultiSelectList(listPassphrases, "id", "value");
            ViewData["Passphrases"] = mslPassphrases;

            ViewData["Roles"] = this.GetRolesInList(form, ActionCreate);

            return View(user);
        }
Beispiel #4
0
        public void CanCreateUserAndRole()
        {
            IRepository<Role> repoA = new RoleRepository();
            Role role1 = new Role();
            role1.Name = "PruebaRol1";
            role1.Description = "Prueba descriptiva rol 1";
            Role role2 = new Role();
            role2.Name = "PruebaRol2";
            role2.Description = "Prueba descriptiva rol 2";

            repoA.Save(role1);
            repoA.Save(role2);

            IRepository<User> repoB = new UserRepository();
            User user1 = new User();
            user1.DocumentId = 11111;
            user1.LoginEmail = "*****@*****.**";
            user1.FirstName = "Usuario prueba nombre 1";
            user1.MiddleName = "Usuario prueba nombre 2";
            user1.LastName1 = "Usuario prueba apellido 1";
            user1.LastName2 = "Usuario prueba apellido 2";
            user1.PhoneNumber = "457-4334(90)";
            user1.IsActive = true;
            user1.Password = "******";

            UserRole userRole1 = new UserRole();
            userRole1.Role = role1;
            userRole1.User = user1;
            UserRole userRole2 = new UserRole();
            userRole2.Role = role2;
            userRole2.User = user1;

            user1.Roles.Add(userRole1);
            user1.Roles.Add(userRole2);

            repoB.Save(user1);
        }
Beispiel #5
0
        private User RemoveExtraSpaces(User user)
        {
            user.DocumentId = !String.IsNullOrWhiteSpace(user.DocumentId.ToString()) ? Convert.ToDouble(user.DocumentId.ToString().Trim()) : 0;
            user.LoginEmail = !String.IsNullOrWhiteSpace(user.LoginEmail) ? user.LoginEmail.Trim() : null;
            user.FirstName = !String.IsNullOrWhiteSpace(user.FirstName) ? user.FirstName.Trim() : null;
            user.MiddleName = !String.IsNullOrWhiteSpace(user.MiddleName) ? user.MiddleName.Trim() : null;
            user.LastName1 = !String.IsNullOrWhiteSpace(user.LastName1) ? user.LastName1.Trim() : null;
            user.LastName2 = !String.IsNullOrWhiteSpace(user.LastName2) ? user.LastName2.Trim() : null;
            user.PhoneNumber = !String.IsNullOrWhiteSpace(user.PhoneNumber) ? user.PhoneNumber.Trim() : null;

            return user;
        }
Beispiel #6
0
 private void AddRolesInstances(User user, FormCollection form)
 {
     var roles = form["RoleIds"].Replace(",", "");
     foreach (Object role in roles)
     {
         UserRole userRole = new UserRole();
         userRole.Role = dbR.GetById(Convert.ToInt32(role.ToString()));
         userRole.User = user;
         user.Roles.Add(userRole);
     }
 }