public async Task <IHttpActionResult> add([FromBody] UserVM entity)
        {
            string BackUpFile       = ConfigurationManager.AppSettings["backUpFile"].ToString();
            string DatabaseFilePath = ConfigurationManager.AppSettings["DatabaseFilesPath"].ToString();
            string _databaseName    = ConfigurationManager.AppSettings["CS_InitialCatalog"].ToString();

            _databaseName                  = userService.CopyDataBase(BackUpFile, DatabaseFilePath, _databaseName);
            entity.CS_DataSource           = ConfigurationManager.AppSettings["CS_DataSource"].ToString();
            entity.CS_InitialCatalog       = _databaseName; // ConfigurationManager.AppSettings["CS_InitialCatalog"].ToString();
            entity.CS_Password             = ConfigurationManager.AppSettings["CS_Password"].ToString();
            entity.CS_UserId               = ConfigurationManager.AppSettings["CS_UserId"].ToString();
            entity.COMPANY_ACTIVATION_CODE = RandomActivation.Generate(30, 40);
            entity.IS_ACTIVATED            = true;

            var result = await userService.InsertAsync(entity);

            await LogData(null, entity.UID.ToString());

            return(Ok(result));
        }
        public async Task <HttpResponseMessage> Registering(HttpRequestMessage request)
        {
            if (!request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var data = await Request.Content.ParseMultipartAsync();

            UserVM UserEntity = getUserEntity(data.Fields);

            if (data.Files.ContainsKey("file"))
            {
                var file = data.Files["file"].File;
                UserEntity.COMPANY_LOGO = file;
                var fileName = data.Files["file"].Filename;
            }
            if (data.Fields.ContainsKey("description"))
            {
                var description = data.Fields["description"].Value;
            }


            try
            {
                var userDB = new User();
                try
                {
                    string BackUpFile       = ConfigurationManager.AppSettings["backUpFile"].ToString();
                    string DatabaseFilePath = ConfigurationManager.AppSettings["DatabaseFilesPath"].ToString();
                    string _databaseName    = ConfigurationManager.AppSettings["CS_InitialCatalog"].ToString();
                    _databaseName                          = userService.CopyDataBase(BackUpFile, DatabaseFilePath, _databaseName);
                    UserEntity.CS_DataSource               = ConfigurationManager.AppSettings["CS_DataSource"].ToString();
                    UserEntity.CS_InitialCatalog           = _databaseName; // ConfigurationManager.AppSettings["CS_InitialCatalog"].ToString();
                    UserEntity.CS_Password                 = ConfigurationManager.AppSettings["CS_Password"].ToString();
                    UserEntity.CS_UserId                   = ConfigurationManager.AppSettings["CS_UserId"].ToString();
                    UserEntity.COMPANY_ACTIVATION_CODE     = RandomActivation.Generate(30, 40);
                    UserEntity.IS_ACTIVATED                = true;
                    UserEntity.ActivationRequestedDateTime = DateTime.Now;
                    UserEntity.LanguageID                  = 1;
                    UserEntity.IsAdmin                     = true;
                    userDB = await userService.InsertAsync(UserEntity);

                    await LogData(userDB.UID.ToString());

                    if (userDB != null)
                    {
                        UserEntity.COMPANY_LOGO = null;
                        await userService.InsertInnerUserAsync(UserEntity);
                        await LogData(UserEntity.UID.ToString());
                    }
                }
                catch (Exception ex) { string str = ex.Message; }


                string sendFrom   = WebConfigurationManager.AppSettings["email"].ToString();
                string Password   = WebConfigurationManager.AppSettings["emailPass"].ToString();
                string serverHost = WebConfigurationManager.AppSettings["serverHost"].ToString();
                int    serverPort = Convert.ToInt32(WebConfigurationManager.AppSettings["serverPort"].ToString());

                string BaseUrl = WebConfigurationManager.AppSettings["siteUrllocal"].ToString();

                string emailSubject     = "رابط تفعيل حساب الشركة علي Resorterp";
                string emailDescription = "شرفنا بزيارة موقعنا الالكتروني <br> <a href='http://www.Resorterp.com/'>http://www.Resorterp.com/</a> ";
                string emailBody        = "";
                using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("../Resources/EmailBody.html")))
                {
                    emailBody = reader.ReadToEnd();
                }

                string activationLink = BaseUrl + "activation" + "?UID=" + "" + userDB.ID.ToString() + "" + "&AC=" + userDB.COMPANY_ACTIVATION_CODE.ToString();
                emailBody = emailBody.Replace("{Description}", emailDescription);
                emailBody = emailBody.Replace("{UserName}", UserEntity.COMPANY_AR_NAME);
                emailBody = emailBody.Replace("{Link}", "<a href='" + activationLink + "'>" + BaseUrl + "activation" + "</a>");

                /***********************************************************************************************************/
                var inlineLogo = new LinkedResource(HttpContext.Current.Server.MapPath("~/Resources/logo4.png"));
                inlineLogo.ContentId = Guid.NewGuid().ToString();

                /***********************************************************************************************************/
                emailBody = emailBody.Replace("{logo}", String.Format(@"<img src=""cid:{0}"" style='background-color: darkgray;width: 94%;height:160px !important'>", inlineLogo.ContentId));

                bool res = await userService.SendMail(sendFrom, Password, UserEntity.COMPANY_EMAIL, emailSubject, emailBody, null, serverHost, serverPort, inlineLogo);

                if (res)
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent("Register Completed...")
                    });
                }
                else
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent("Mail not sent...")
                    });
                }
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }