public static int InserToUser(string userName, string passWord)
 {
     using (var context = new Atiran.Connections.AtiranAccModel.AccModelEntities(Atiran.Connections.AtiranAccModel.ConnectionInfo.BuildConnectionString()))
     {
         int result = 0;
         try
         {
             Atiran.Connections.AtiranAccModel.User usr = new Atiran.Connections.AtiranAccModel.User()
             {
                 UserName     = userName,
                 UserPassWord = System.Text.Encoding.UTF8.GetBytes(passWord),
                 Active       = true
             };
             context.Users.Add(usr);
             context.SaveChanges();
             context.AddUser(usr.UserID, Connections.AtiranAccModel.ConnectionInfo.DatabaseName.ToString());
             result = usr.UserID;
             return(result);
         }
         catch (Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.Message);
             return(result);
         }
     }
 }
 public static bool EditUser(int UserID, string userName, string passWord)
 {
     using (var context = new Atiran.Connections.AtiranAccModel.AccModelEntities(Atiran.Connections.AtiranAccModel.ConnectionInfo.BuildConnectionString()))
     {
         bool result = false;
         try
         {
             Atiran.Connections.AtiranAccModel.User usr = context.Users.Where(i => i.UserID == UserID).FirstOrDefault();
             {
                 //usr.UserName = userName;
                 usr.UserPassWord = System.Text.Encoding.UTF8.GetBytes(passWord);
             };
             context.SaveChanges();
             result = true;
             return(result);
         }
         catch (Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.Message);
             return(result);
         }
     }
 }
Exemple #3
0
        public static bool InsertIntoUserPersonalization(
            List <Atiran.Connections.AtiranAccModel.UserPersonalizationForColor> UserPersonalizationForColor,
            List <Atiran.Connections.AtiranAccModel.UserPersonalizationForFont> UserPersonalizationForFont, string ImageAddres, bool Default = false)
        {
            //Color
            var PersonalizationColorID = PersonalizationForColor.Where(w => UserPersonalizationForColor.Any(a =>
                                                                                                            a.ControlColorID == w.ControlColorID && a.ControlNameID == w.ControlNameID)).Select(s => s.PersonalizationColorID).ToList();
            //Font
            List <int> PersonalizationFontID = PersonalizationForFont.Where(w => UserPersonalizationForFont.Any(a => a.ControlNameID == w.ControlNameID)).Select(s => s.PersonalizationFontID).ToList();

            using (var ctx = new Atiran.Connections.AtiranAccModel.AccModelEntities(Connections.AtiranAccModel.ConnectionInfo.BuildConnectionString()))
            {
                ctx.Database.CommandTimeout = 0;
                using (var trans = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        if (Default)
                        {
                            //Color
                            ctx.UserPersonalizationForColors.RemoveRange(ctx.UserPersonalizationForColors.Where(w => w.UserID == GetCurrentSysUser.Instance.UserID).ToList());

                            //Font
                            ctx.UserPersonalizationForFonts.RemoveRange(ctx.UserPersonalizationForFonts.Where(w => w.UserID == GetCurrentSysUser.Instance.UserID).ToList());
                            GetCurrentSysUser.Instance.BackGroundAddress = "";
                            Atiran.Connections.AtiranAccModel.User temp = ctx.Users.FirstOrDefault(f =>
                                                                                                   f.UserID == GetCurrentSysUser.Instance.UserID);
                            {
                                temp.BackGroundAddress = "";
                                GetCurrentSysUser.Instance.BackGroundAddress = "";
                            }
                        }
                        else
                        {
                            //Color
                            ctx.UserPersonalizationForColors.RemoveRange(ctx.UserPersonalizationForColors.Where(w => PersonalizationColorID.Contains(w.PersonalizationColorID)));

                            ctx.UserPersonalizationForColors.AddRange(UserPersonalizationForColor);

                            //Font
                            ctx.UserPersonalizationForFonts.RemoveRange(ctx.UserPersonalizationForFonts.Where(w => PersonalizationFontID.Contains(w.PersonalizationFontID)).ToList());

                            ctx.UserPersonalizationForFonts.AddRange(UserPersonalizationForFont);

                            if (ImageAddres != GetCurrentSysUser.Instance.BackGroundAddress)
                            {
                                Atiran.Connections.AtiranAccModel.User temp = ctx.Users.FirstOrDefault(f =>
                                                                                                       f.UserID == GetCurrentSysUser.Instance.UserID);
                                {
                                    temp.BackGroundAddress = ImageAddres;
                                    GetCurrentSysUser.Instance.BackGroundAddress = ImageAddres;
                                }
                            }
                        }

                        //save
                        ctx.BulkSaveChanges();
                        trans.Commit();

                        Atiran.Connections.Operaions.UserPersonalizationOp.UserPersonalizationOperaion.SetUserPersonalization();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.ToString());
                        trans.Rollback();
                        return(false);
                    }
                }
            }
        }