Пример #1
0
        public virtual ActionResult AddEdit(T item)
        {
            TestUpdate(item);

            con.SaveChanges();

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public void Task(Models.Entities con, Test_Schedule model, Mutex mutex, bool saveFlags)
        {
            try
            {
                if (saveFlags)
                {
                    model.Flag_Start = 1;
                    con.SaveChanges();
                }

                var db    = model.Test_Db;
                var url   = model.Test_Url;
                var users = model.Test_Url.Test_User;

                foreach (var tgRef in model.Test_Group.Test_Group_Ref)
                {
                    foreach (var user in users)
                    {
                        var result = new AspMvcEf.Models.Test_Result()
                        {
                            Id = 0,
                            Test_Schedule_Id = model.Id,
                            Test_Group_Id    = tgRef.Test_Group_Id,
                            Test_Id          = tgRef.Test_Id,
                            Flag_Ok          = null,
                            Result           = null,
                            Time_Start       = DateTime.Now,
                            Time_Stop        = null
                        };
                        try
                        {
                            //Models.SeleniumTest.Run(tgRef.Test.Test_Type.Type, tgRef.Test.Insurance_Id, user.Username, user.Password, url.Url, db.CisConnectionString, db.WebConnectionString);
                            result.Result  = "";
                            result.Flag_Ok = 1;
                        }
                        catch (Exception e)
                        {
                            result.Result  = e.ToString();
                            result.Flag_Ok = 0;
                        }
                        result.Time_Stop        = DateTime.Now;
                        con.Entry(result).State = System.Data.Entity.EntityState.Added;
                        con.SaveChanges();
                    }
                }

                if (saveFlags)
                {
                    model.Flag_Stop = 1;
                    con.SaveChanges();
                }
            }
            finally
            {
                mutex.Close();
            }
        }
        public ActionResult Erreur(long?id, Models.CatchMe_Exception row)
        {
            ViewBag.PreviousUrl = TempData["PreviousUrl"] != null ? TempData["PreviousUrl"] : GetPreviousUrl();

            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            var ex = sql.CatchMe_Exception.Where(x => x.CodeCatch == id).FirstOrDefault();

            if (ex != null)
            {
                if (ModelState.IsValid)
                {
                    ex.CodeStatus  = row.CodeStatus;
                    ex.DateStatus  = DateTime.Now;
                    ex.LoginStatus = User?.Identity?.Name;

                    //try
                    //{
                    //   ex.Masquer = true;
                    sql.SaveChanges();
                    //}
                    //catch (Exception rrr)
                    //{
                    //}


                    var Next = sql.CatchMe_Exception.Where(x => x.CodeCatch > id && x.Masquer == false).Select(x => x.CodeCatch).FirstOrDefault();
                    if (Next > 0)
                    {
                        return(RedirectToAction(RouteData.Values["action"].ToString(), new { id = Next }));
                    }
                    else
                    {
                        return(Redirect(ViewBag.PreviousUrl));
                    }
                }
                else
                {
                    return(View(RouteData.Values["action"].ToString(), ex));
                }
            }


            return(View("Erreur", row));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sessionGuiId"></param>
 /// <returns></returns>
 public bool UpdateSession(Guid sessionGuiId)
 {
     using (Models.Entities entity = new Models.Entities())
     {
         try
         {
             Models.SessionManagement sessionManagement = new Models.SessionManagement();
             var result = entity.SessionManagements.SingleOrDefault(w => w.SessionGuiId == sessionGuiId);
             if (result != null)
             {
                 result.EndDate = DateTime.Now.AddHours(1);
                 entity.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception ex)
         {
             entity.Dispose();
             throw;
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="ipAddress"></param>
        /// <param name="machineName"></param>
        /// <returns></returns>
        public bool CreateSession(string userName)
        {
            using (Models.Entities entity = new Models.Entities())
            {
                try
                {
                    Models.SessionManagement sessionManagement = new Models.SessionManagement();

                    sessionManagement.SessionGuiId = Guid.NewGuid();
                    sessionManagement.CreatedDate  = DateTime.Now;
                    sessionManagement.EndDate      = DateTime.Now.AddHours(1);
                    sessionManagement.IpAddress    = GetIp();
                    sessionManagement.MachineName  = null;

                    entity.SessionManagements.Add(sessionManagement);
                    entity.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    entity.Dispose();
                    throw;
                }
            }
        }
Пример #6
0
        public bool DeleteUser(string userName)
        {
            try
            {
                var               en     = new Models.Entities();
                aspnet_Users      u      = null;
                aspnet_Membership member = null;
                try
                {
                    u      = en.aspnet_Users.First(m => m.UserName == userName);
                    member = en.aspnet_Membership.First(m => m.UserId == u.UserId);

                    en.DeleteObject(member);
                    en.DeleteObject(u);

                    en.SaveChanges();

                    return(true);
                }
                catch
                {
                    throw new ArgumentException("注销失败");
                }
            }
            catch
            {
                throw;
            }
        }
Пример #7
0
        public string SetValidationCode(string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentNullException("用户名为空");
            }

            try
            {
                var          en = new Models.Entities();
                aspnet_Users u  = null;
                try
                {
                    u = en.aspnet_Users.First(m => m.UserName == userName);
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                // set a 20-lengthed validation string (code), it's only validate in 24 hours
                u.ValidationCode = (new Utilities.RandString()).Generate();
                u.validUntil     = DateTime.Now.AddDays(1);

                en.ApplyCurrentValues("aspnet_Users", u);
                en.SaveChanges();

                return(u.ValidationCode);
            }
            catch
            {
                throw;
            }
        }
        public ActionResult AddRecView(Models.Recipes recipe, HttpPostedFileBase image1)
        {
            if (ModelState.IsValid)
            {
                recipe.user_ID     = User.Identity.GetUserId();
                recipe.recipe_date = DateTime.Now;
                if (image1 != null)
                {
                    recipe.picture = new byte[image1.ContentLength];
                    image1.InputStream.Read(recipe.picture, 0, image1.ContentLength);
                }
                else
                {
                    recipe.picture = Encoding.ASCII.GetBytes("0000");
                }
                db.Recipes.Add(recipe);
                db.SaveChanges();
            }

            return(RedirectToAction("RecipesView", "Home"));
        }
Пример #9
0
        public void SetPhotoUrl(string userName, string photoUrl)
        {
            if (string.IsNullOrWhiteSpace(photoUrl))
            {
                throw new ArgumentNullException("头像图片地址为空");
            }

            try
            {
                var          en = new Models.Entities();
                aspnet_Users u  = en.aspnet_Users.First(m => m.UserName == userName);

                u.PhotoUrl = photoUrl;
                en.ApplyCurrentValues("aspnet_Users", u);
                en.SaveChanges();
            }
            catch
            {
                throw new ArgumentException("用户名不存在");
            }
        }
Пример #10
0
        public void SetEmail(string userName, string newEmail)
        {
            if (string.IsNullOrEmpty(newEmail))
            {
                throw new ArgumentException("新的Email为空");
            }

            if (GetUserNameByEmail(newEmail) != null)
            {
                throw new ArgumentException("Email已经被注册");
            }

            try
            {
                var               en     = new Models.Entities();
                aspnet_Users      u      = null;
                aspnet_Membership member = null;
                try
                {
                    u      = en.aspnet_Users.First(m => m.UserName == userName);
                    member = en.aspnet_Membership.First(m => m.UserId == u.UserId);
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                u.Email             = newEmail;
                member.Email        = newEmail;
                member.LoweredEmail = newEmail.ToLower();

                en.ApplyCurrentValues("aspnet_Users", u);
                en.ApplyCurrentValues("aspnet_Membership", member);
                en.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
Пример #11
0
        public string SetValidationCode(string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentNullException("用户名为空");
            }

            try
            {
                var en = new Models.Entities();
                aspnet_Users u = null;
                try
                {
                    u = en.aspnet_Users.First(m => m.UserName == userName);
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                // set a 20-lengthed validation string (code), it's only validate in 24 hours
                u.ValidationCode = (new Utilities.RandString()).Generate();
                u.validUntil = DateTime.Now.AddDays(1);

                en.ApplyCurrentValues("aspnet_Users", u);
                en.SaveChanges();

                return u.ValidationCode;
            }
            catch
            {
                throw;
            }
        }
Пример #12
0
        public void SetPhotoUrl(string userName, string photoUrl)
        {
            if (string.IsNullOrWhiteSpace(photoUrl))
            {
                throw new ArgumentNullException("头像图片地址为空");
            }

            try
            {
                var en = new Models.Entities();
                aspnet_Users u = en.aspnet_Users.First(m => m.UserName == userName);

                u.PhotoUrl = photoUrl;
                en.ApplyCurrentValues("aspnet_Users", u);
                en.SaveChanges();
            }
            catch
            {
                throw new ArgumentException("用户名不存在");
            }
        }
Пример #13
0
        public void SetEmail(string userName, string newEmail)
        {
            if (string.IsNullOrEmpty(newEmail))
            {
                throw new ArgumentException("新的Email为空");
            }

            if (GetUserNameByEmail(newEmail) != null)
            {
                throw new ArgumentException("Email已经被注册");
            }

            try
            {
                var en = new Models.Entities();
                aspnet_Users u = null;
                aspnet_Membership member = null;
                try
                {
                    u = en.aspnet_Users.First(m => m.UserName == userName);
                    member = en.aspnet_Membership.First(m => m.UserId == u.UserId);
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                u.Email = newEmail;
                member.Email = newEmail;
                member.LoweredEmail = newEmail.ToLower();

                en.ApplyCurrentValues("aspnet_Users", u);
                en.ApplyCurrentValues("aspnet_Membership", member);
                en.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
Пример #14
0
        public void ResetPassword(string validationCode, string newPassword)
        {
            if (string.IsNullOrEmpty(validationCode))
            {
                throw new ArgumentNullException("验证码为空");
            }

            if (string.IsNullOrEmpty(newPassword))
            {
                throw new ArgumentNullException("新密码不能为空");
            }

            if (newPassword.Length < 6)
            {
                throw new ArgumentNullException("新密码不能少于6个字符");
            }

            try
            {
                var en = new Models.Entities();
                aspnet_Users u = null;
                try
                {
                    u = en.aspnet_Users.First(m => m.ValidationCode == validationCode);
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                if (((DateTime)u.validUntil).CompareTo(DateTime.Now) < 0)
                {
                    throw new ArgumentException("验证码过期");
                }

                aspnet_Membership member = en.aspnet_Membership.First(m => m.UserId == u.UserId);

                var userName = u.UserName;
                var email = member.Email;

                var cd = member.CreateDate;
                var lld = member.LastLoginDate;
                var unc = u.UserNameChanged;

                // delete old user
                en.DeleteObject(member);
                en.DeleteObject(u);

                en.SaveChanges();

                // recreate the user
                CreateUser(userName, newPassword, email);

                // copy the old user's attrs to the new one
                try
                {
                    var newU = en.aspnet_Users.First(m => m.UserName == userName);
                    var newMember = en.aspnet_Membership.First(m => m.UserId == newU.UserId);

                    newU.UserNameChanged = unc;
                    newMember.CreateDate = cd;
                    newMember.LastLoginDate = lld;

                    en.ApplyCurrentValues("aspnet_Users", newU);
                    en.ApplyCurrentValues("aspnet_Membership", newMember);

                    en.SaveChanges();
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                return;
            }
            catch
            {
                throw;
            }
        }
Пример #15
0
        public bool DeleteUser(string userName)
        {
            try
            {
                var en = new Models.Entities();
                aspnet_Users u = null;
                aspnet_Membership member = null;
                try
                {
                    u = en.aspnet_Users.First(m => m.UserName == userName);
                    member = en.aspnet_Membership.First(m => m.UserId == u.UserId);

                    en.DeleteObject(member);
                    en.DeleteObject(u);

                    en.SaveChanges();

                    return true;
                }
                catch
                {
                    throw new ArgumentException("注销失败");
                }
            }
            catch
            {
                throw;
            }
        }
Пример #16
0
        public void ResetPassword(string validationCode, string newPassword)
        {
            if (string.IsNullOrEmpty(validationCode))
            {
                throw new ArgumentNullException("验证码为空");
            }

            if (string.IsNullOrEmpty(newPassword))
            {
                throw new ArgumentNullException("新密码不能为空");
            }

            if (newPassword.Length < 6)
            {
                throw new ArgumentNullException("新密码不能少于6个字符");
            }

            try
            {
                var          en = new Models.Entities();
                aspnet_Users u  = null;
                try
                {
                    u = en.aspnet_Users.First(m => m.ValidationCode == validationCode);
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                if (((DateTime)u.validUntil).CompareTo(DateTime.Now) < 0)
                {
                    throw new ArgumentException("验证码过期");
                }

                aspnet_Membership member = en.aspnet_Membership.First(m => m.UserId == u.UserId);

                var userName = u.UserName;
                var email    = member.Email;

                var cd  = member.CreateDate;
                var lld = member.LastLoginDate;
                var unc = u.UserNameChanged;

                // delete old user
                en.DeleteObject(member);
                en.DeleteObject(u);

                en.SaveChanges();

                // recreate the user
                CreateUser(userName, newPassword, email);

                // copy the old user's attrs to the new one
                try
                {
                    var newU      = en.aspnet_Users.First(m => m.UserName == userName);
                    var newMember = en.aspnet_Membership.First(m => m.UserId == newU.UserId);

                    newU.UserNameChanged    = unc;
                    newMember.CreateDate    = cd;
                    newMember.LastLoginDate = lld;

                    en.ApplyCurrentValues("aspnet_Users", newU);
                    en.ApplyCurrentValues("aspnet_Membership", newMember);

                    en.SaveChanges();
                }
                catch
                {
                    throw new ArgumentException("用户名不存在");
                }

                return;
            }
            catch
            {
                throw;
            }
        }
        public ActionResult ErrorFile(Models.ErrorFilePage row)
        {
            ViewBag.PreviousUrl = TempData["PreviousUrl"] != null ? TempData["PreviousUrl"] : GetPreviousUrl();

            bool Supprimer = false;
            bool Importer  = false;


            if (Request.Form["Action"] != null)
            {
                if (Request.Form["Action"].IndexOf("Imp", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    Importer = true;
                }
                else if (Request.Form["Action"].IndexOf("Sup", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    Supprimer = true;
                }
            }



            System.Web.Script.Serialization.JavaScriptSerializer scriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            var Fichier = row.Fichiers.FirstOrDefault();

            if (Fichier != null)
            {
                byte[]           input   = null;
                int              FileLen = Fichier.ContentLength;
                System.IO.Stream MyStream;
                input = new byte[FileLen];

                MyStream = Fichier.InputStream;
                MyStream.Read(input, 0, FileLen);

                row.MyEx = scriptSerializer.Deserialize <MyException>(System.Text.Encoding.UTF8.GetString(input)).EEE();
            }
            else if (!string.IsNullOrWhiteSpace(row.Fichier))
            {
                var filename = System.IO.Path.Combine(Server.MapPath("~/App_Data"), row.Fichier + ".ERDUMP");

                if (Supprimer)
                {
                    System.IO.File.Delete(filename);
                    row.MyEx = null;
                }
                else
                {
                    row.MyEx = scriptSerializer.Deserialize <MyException>(System.IO.File.ReadAllText(filename)).EEE();
                }
            }
            else
            {
                row.MyEx = null;
            }

            //  Except = exception.EEE();

            if (Importer && row.MyEx != null)
            {
                try
                {
                    //throw new System.Data.Entity.Validation.DbEntityValidationException();

                    var sql = new Models.Entities();
                    sql.CatchMe_Exception.Add(row.MyEx);
                    sql.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException e)
                {
                    ViewBag.ErrorMessage = CatchException.Dump(e).ToString().Replace("\n", "<br/>");
                    return(View(row));
                }

                if (!string.IsNullOrWhiteSpace(row.Fichier))
                {
                    var filename = System.IO.Path.Combine(Server.MapPath("~/App_Data"), row.Fichier + ".ERDUMP");
                    System.IO.File.Delete(filename);
                }

                return(RedirectToAction("Erreur", new { id = row.MyEx.CodeCatch }));
            }



            return(View(row));
        }