public string InsertAccount(HttpPostedFileBase avatar, string password, string username, string fullname, string email, string address, string phone, string icode, string dob, int roleID)
        {
            string fileName = "default_avatar.png";

            try
            {
                Account acc = new Account()
                {
                    Username     = username,
                    Password     = password,
                    Avatar       = fileName,
                    Fullname     = fullname,
                    Email        = email,
                    Address      = address,
                    Phone        = phone,
                    IdentifyCode = icode,
                    DOB          = DateTime.ParseExact(dob, "dd - MM - yyyy", null),
                    RoleID       = roleID
                };

                var id_inserted = AccountDAO.AddAccount(acc);
                acc.ID = id_inserted;

                if (avatar != null)
                {
                    //fileName = System.IO.Path.GetFileName(avatar.FileName) + "/" + id_inserted;
                    fileName = "avatar_" + id_inserted + ".png";
                    string path_avatar = System.IO.Path.Combine(Server.MapPath("~/images/avatarAccount"), fileName);
                    // file is uploaded
                    avatar.SaveAs(path_avatar);
                }

                acc.Avatar = fileName;

                AccountDAO.UpdateAccout(acc);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return("success");
        }
        public byte[] Register(byte[] data, ClientPeer client, MainServer server)
        {
            AccountInfo recive = MessageTool.ProtoBufDataDeSerialize <AccountInfo>(data);

            bool        res = mAccount.GetAccountByAccountId(client.MySQLConn, recive.AccountId);
            MSGCallBack msg;

            if (res)
            {
                msg = new MSGCallBack(ReturnCode.Fail);
            }
            else
            {
                mAccount.AddAccount(client.MySQLConn, recive.AccountId,
                                    recive.AccountName, recive.Password, 1001, client.ImgPathDic[1001]);
                client.IsOnLine = true;
                msg             = new MSGCallBack(ReturnCode.Success);
            }
            return(MessageTool.ProtoBufDataSerialize(msg));
        }
 public ActionResult AddUser([Bind(Include = "Fullname, Lastname, Username, Password, Phone, Address, IdentifyCode,Role")] Account login)
 {
     AccountDAO.AddAccount(login);
     return(RedirectToAction("Index"));
 }