コード例 #1
0
        //Add new record
        public static int AddRecord(eUsers eobj, string Groups)
        {
            int retval = 0;

            using (OneFineRateEntities db = new OneFineRateEntities())
            {
                try
                {
                    OneFineRate.tblUserM dbuser = (OneFineRate.tblUserM)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblUserM());

                    var dbobj = db.tblUserMs.SingleOrDefault(u => u.sUserName == dbuser.sUserName);
                    if (dbobj != null)
                    {
                        return(2);
                    }

                    dbobj = db.tblUserMs.SingleOrDefault(u => u.sEmail == dbuser.sEmail);
                    if (dbobj != null)
                    {
                        return(3);
                    }

                    db.tblUserMs.Add(dbuser);
                    db.SaveChanges();

                    try
                    {
                        var obj = db.tblUserGroupMs.Where(u => u.iUserId == dbuser.iUserId);
                        db.tblUserGroupMs.RemoveRange(obj);
                    }
                    catch (Exception) { }


                    var grps = Groups.Split(',').ToList();
                    db.tblUserGroupMs.AddRange(grps.Select(x => new tblUserGroupM()
                    {
                        cStatus        = "A",
                        dtActionDate   = DateTime.Now,
                        dtCreationDate = DateTime.Now,
                        iActionBy      = dbuser.iActionBy,
                        iCreatedBy     = dbuser.iActionBy,
                        iGroupId       = Convert.ToInt32(x),
                        iUserId        = dbuser.iUserId
                    }));
                    db.SaveChanges();
                    retval = 1;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(retval);
        }
コード例 #2
0
        //Get Single Record
        public static eUsers GetSingleRecordById(int id)
        {
            eUsers eobj = new eUsers();

            using (OneFineRateEntities db = new OneFineRateEntities())
            {
                var dbobj = db.tblUserMs.SingleOrDefault(u => u.iUserId == id);
                if (dbobj != null)
                {
                    eobj = (eUsers)OneFineRateAppUtil.clsUtils.ConvertToObject(dbobj, eobj);
                }
            }
            return(eobj);
        }
コード例 #3
0
        public string AddUsers(string firstname, string lastname, string emailID, string contact, bool Active, string Groups)
        {
            object result    = null;
            string strReturn = string.Empty;

            try
            {
                eUsers eObj = new eUsers();
                eObj.sUserName = emailID;
                byte[] b        = new byte[1];
                string Password = emailID.Substring(0, emailID.IndexOf("@")).ToLower();
                Password = SimpleHash.ComputeHash(Password, "SHA1", b);

                eObj.sPassword    = Password;
                eObj.sFirstName   = firstname;
                eObj.sLastName    = lastname;
                eObj.sEmail       = emailID;
                eObj.sContact     = contact;
                eObj.dtCreatedOn  = DateTime.Now;
                eObj.dtActionDate = DateTime.Now;
                eObj.cStatus      = Active ? "A" : "D";
                eObj.iActionBy    = ((OneFineRateBLL.BL_Login.UserDetails)Session["UserDetails"]).iUserId;

                int i = BL_Users.AddRecord(eObj, Groups.Substring(0, Groups.Length - 1));
                if (i == 1)
                {
                    result = new { st = 1, msg = clsUtils.ErrorMsg("User", 1) };
                }
                else
                {
                    result = new { st = 0, msg = clsUtils.ErrorMsg("User", 0) };
                }
            }
            catch (Exception ex)
            {
                result = new { st = 0, msg = clsUtils.ErrorMsg("", 3) };
            }
            strReturn = OneFineRateAppUtil.clsUtils.ConvertToJson(result);
            return(strReturn);
        }
コード例 #4
0
        public string UpdateUsers(string Usersname, string firstname, string lastname, string emailID, string contact, bool Active, int id, string Groups)
        {
            object result    = null;
            string strReturn = string.Empty;

            try
            {
                eUsers Obj = new eUsers();
                Obj              = BL_Users.GetSingleRecordById(id);
                Obj.sUserName    = emailID;
                Obj.sFirstName   = firstname;
                Obj.sLastName    = lastname;
                Obj.sEmail       = emailID;
                Obj.sContact     = contact;
                Obj.dtCreatedOn  = DateTime.Now;
                Obj.dtActionDate = DateTime.Now;
                Obj.cStatus      = Active ? "A" : "I";
                int a = ((OneFineRateBLL.BL_Login.UserDetails)Session["UserDetails"]).iUserId;
                Obj.iActionBy = a;
                int i = BL_Users.UpdateRecord(Obj, Groups.Substring(0, Groups.Length - 1));
                if (i == 1)
                {
                    result = new { st = 1, msg = clsUtils.ErrorMsg("User", 2) };
                }
                else
                {
                    result = new { st = 0, msg = clsUtils.ErrorMsg("User", 0) };
                }
            }
            catch (Exception)
            {
                result = new { st = 0, msg = clsUtils.ErrorMsg("", 3) };
            }
            strReturn = OneFineRateAppUtil.clsUtils.ConvertToJson(result);
            return(strReturn);
        }