Beispiel #1
0
 public string Add(Member member)
 {
     try
     {
         if (member != null)
         {
             if (!IsDuplicate(string.Empty, member.UserName))
             {
                 string UserID = CommonConstant.GetFieldValueString(Session[CommonConstant.SessionUserID]);
                 RSACrypto crypto = new RSACrypto();
                 member.MemberID = Guid.NewGuid().ToString();
                 member.Password = crypto.Encrypt(CommonConstant.DefaultPassword);
                 member.DealerID = UserID;
                 member.UpdateBy = UserID;
                 member.UpdateDate = DateTime.Now;
                 member.CreateBy = UserID;
                 member.CreateDate = DateTime.Now;
                 db.Members.Add(member);
                 db.SaveChanges();
                 return "Success";
             }
             else
             {
                 return "This username is already in used.";
             }
         }
     }
     catch (Exception ex)
     {
         LogFile.writeLogFile(DateTime.Now, "MemberController", ex.ToString());
     }
     return "Add new member failed";
 }
Beispiel #2
0
        public string Update(Member member)
        {
            try
            {
                if (member != null)
                {
                    if (!IsDuplicate(member.MemberID, member.UserName))
                    {

                        Member mem = db.Members.Find(member.MemberID);
                        mem.UserName = member.UserName;
                        mem.MemberName = member.MemberName;
                        mem.MemberTypeID = member.MemberTypeID;
                        //mem.Password = member.Password;
                        mem.Email = member.Email;
                        mem.Address = member.Address;
                        mem.Phone = member.Phone;
                        mem.UpdateBy = CommonConstant.GetFieldValueString(Session[CommonConstant.SessionUserID]);
                        mem.UpdateDate = DateTime.Now;
                        db.Entry(mem).State = EntityState.Modified;
                        db.SaveChanges();
                        return "Success";
                    }
                    else
                    {
                        return "This username is already in used.";
                    }
                }
            }
            catch (Exception ex)
            {
                LogFile.writeLogFile(DateTime.Now, "MemberController", ex.ToString());

            }
            return "Update failed";
        }