Beispiel #1
0
        public dynamic GetVmNames()
        {
            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                return context.VMThresholds.Select(item => new { item.Id, item.VMName }).ToList();
            }


        }
Beispiel #2
0
        public List<VMUtilization> GetVmUtilizationDataBasedOnId(int id)
        {
            List<VMUtilization> _vmUtilization = new List<VMUtilization>();

            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                _vmUtilization = (from item in context.VMUtilizations
                                  where item.VMId == id
                                  select item).ToList();
            }

            return _vmUtilization;
        }
Beispiel #3
0
 public ActionResult Register(User user)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
             {
                 User newUser = new User();
                // var newUser = context.Users.Create();
                 newUser.Email = user.Email;
                 newUser.Password = user.Password;
                 newUser.Username = user.Username;
                 newUser.FirstName = user.FirstName;
                 newUser.LastName = user.LastName;
               
                 newUser.CreatedDate = DateTime.Now;
                 
                 
                 context.Users.Add(newUser);
                 context.SaveChanges();
                 return RedirectToAction("LogIn", "Home");
             }
         }
         else
         {
             ModelState.AddModelError("", "Data is not correct");
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                 eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                     ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
     return View();
 }
Beispiel #4
0
        public List<VMThreshold> GetVmThresholdData(int id)
        {
            List<VMThreshold> _vmThreshold = new List<VMThreshold>();

            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                if (id != 0)
                {
                    _vmThreshold = (from item in context.VMThresholds
                                    where item.Id == id
                                    select item).ToList();
                }
                else
                {
                    _vmThreshold = (from item in context.VMThresholds
                                    select item).ToList();
                }

            }

            return _vmThreshold;
        }
Beispiel #5
0
        private bool IsValid(string username, string password)
        {
            
            bool IsValid = false;

            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                var user = context.Users.FirstOrDefault(u => u.Username == username);
                if (user != null)
                {
                    if (user.Password ==password)
                    {
                        IsValid = true;
                    }
                }
            }
            return IsValid;
        }
Beispiel #6
0
        public List<VMAutomationRule> GetVmAutomationRuleDataBasedOnId(int id)
        {
            List<VMAutomationRule> _vmAutomationRule = new List<VMAutomationRule>();

            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                if (id != 0)
                {
                    _vmAutomationRule = (from item in context.VMAutomationRules
                                         where item.VMID == id
                                         select item).ToList();
                }
                else
                {
                    _vmAutomationRule = (from item in context.VMAutomationRules
                                         select item).ToList();
                }

            }

            return _vmAutomationRule;
        }
Beispiel #7
0
        public bool AddVMInDB(VMDetails VMData, string BlobLocation, List<SummaryUtil> UtilPattern)
        {
            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                VMThreshold details = new VMThreshold
                {

                    VMName = VMData.Name,
                    Location = VMData.Location,
                    Description = VMData.Description,
                    UtilFileLocation = VMData.UtilFileLocation,
                    Status = "Created"

                };

                context.VMThresholds.Add(details);
                context.SaveChanges();
                var id = details.Id;


                foreach (var u in UtilPattern)
                {

                    // Console.WriteLine(u.UtilizationType);
                    foreach (var tr in u.TimeRanges)
                    {
                        //string InsertUtilPatternQuery = "INSERT into VMAutomationRules (VMID, UtilizationType, StartTime, EndTime) ";
                        //InsertUtilPatternQuery += " VALUES(@VMID, @UtilizationType, @StartTime, @EndTime);";
                        //SqlCommand InsertUtilData = new SqlCommand(InsertUtilPatternQuery, conn);

                        double Start = tr.StartTime ?? 0;
                        double Stop = tr.StopTime ?? 0;

                        TimeSpan StartTime = TimeSpan.FromHours(Start);
                        TimeSpan StopTime = TimeSpan.FromHours(Stop);

                        VMAutomationRule InsertUtilData = new VMAutomationRule
                        {
                            VMID = id,
                            UtilizationType = u.UtilizationType,
                            StartTime = StartTime,
                            EndTime = StopTime
                        };

                        context.VMAutomationRules.Add(InsertUtilData);
                        context.SaveChanges();
                        //InsertUtilData.Parameters.AddWithValue("@VMID", id);
                        //InsertUtilData.Parameters.AddWithValue("@UtilizationType", u.UtilizationType);
                        //InsertUtilData.Parameters.AddWithValue("@StartTime", StartTime);
                        //InsertUtilData.Parameters.AddWithValue("@EndTime", StopTime);

                        //var res = InsertUtilData.ExecuteNonQuery();
                        //Console.WriteLine("{0}, {1}", tr.StartTime, tr.StopTime);
                    }
                }


            }
            //using (var conn = new SqlConnection(ConnString))
            //{
            //    conn.Open();

            //    string InsertVMQuery = "Insert into VMThreshold (VMName, CloudServiceName, Description, UtilFileLocation, Status)";
            //    InsertVMQuery += "values (@VMName, @Location, @Description, @UtilFileLocation, @Status); select SCOPE_IDENTITY();";
            //    //InsertVMQuery += "Select @Id = Scope_Identity()";

            //    SqlCommand InsertVMCommand = new SqlCommand(InsertVMQuery, conn);
            //    InsertVMCommand.Parameters.AddWithValue("@VMName", VMData.Name);
            //    InsertVMCommand.Parameters.AddWithValue("@Location", VMData.Location);
            //    InsertVMCommand.Parameters.AddWithValue("@Description", VMData.Description);
            //    InsertVMCommand.Parameters.AddWithValue("@UtilFileLocation", BlobLocation);
            //    InsertVMCommand.Parameters.AddWithValue("@Status", "Created");
            //    //myCommand.Parameters.Add("@Id", SqlDbType.Int);
            //    var id = InsertVMCommand.ExecuteScalar();

            //    foreach (var u in UtilPattern)
            //    {

            //        Console.WriteLine(u.UtilizationType);
            //        foreach (var tr in u.TimeRanges)
            //        {
            //            string InsertUtilPatternQuery = "INSERT into VMAutomationRules (VMID, UtilizationType, StartTime, EndTime) ";
            //            InsertUtilPatternQuery += " VALUES(@VMID, @UtilizationType, @StartTime, @EndTime);";
            //            SqlCommand InsertUtilData = new SqlCommand(InsertUtilPatternQuery, conn);

            //            double Start = tr.StartTime ?? 0;
            //            double Stop = tr.StopTime ?? 0;

            //            TimeSpan StartTime = TimeSpan.FromHours(Start);
            //            TimeSpan StopTime = TimeSpan.FromHours(Stop);

            //            InsertUtilData.Parameters.AddWithValue("@VMID", id);
            //            InsertUtilData.Parameters.AddWithValue("@UtilizationType", u.UtilizationType);
            //            InsertUtilData.Parameters.AddWithValue("@StartTime", StartTime);
            //            InsertUtilData.Parameters.AddWithValue("@EndTime", StopTime);

            //            var res = InsertUtilData.ExecuteNonQuery();
            //            Console.WriteLine("{0}, {1}", tr.StartTime, tr.StopTime);
            //        }
            //    }

            //}

            return true;
        }
Beispiel #8
0
        public List<VMValue> GetVmValues()
        {
            List<VMValue> _vmValue = new List<VMValue>();

            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                _vmValue = (from item in context.VMValues
                            select item).ToList();
            }

            return _vmValue;
        }
Beispiel #9
0
        public List<VMAction> GetVmActions()
        {
            List<VMAction> _vmAction = new List<VMAction>();

            using (OpsIntel1Entities1 context = new OpsIntel1Entities1())
            {
                _vmAction = (from item in context.VMActions
                             select item).ToList();
            }

            return _vmAction;
        }