Beispiel #1
0
        public ActionResult SaveClient(Client _client)
        {
            if (_client.ClientID == 0)
            {
                string semail = "";
                _client.ApproveOn = System.DateTime.Now;
                var clientInfo = _clientService.GetClientByClientName(_client.EmailID);
                if (clientInfo == null)
                {
                    _client.OrganizationID = HCRGCLIENT.OrganizationID;
                    if (_client.IsEmailSent != true)
                    {
                        string subject;
                        string Email;
                        string msg;

                        if (_client.IsActive == true && _client.IsApproved == true)
                        {
                            _client.TempPassword = _encryptionService.GenratePassword(7);
                            _client.Password     = _encryptionService.HashPassword(_client.TempPassword);
                            Email   = _client.EmailID;
                            subject = "Client Registration & New Password";
                            msg     = @"   <p>Hi " + _client.FirstName + " " + _client.LastName + @",</p>
                            <p>Your password is this : " + _client.TempPassword + @"</p>
                            <p>Thanks!</p>";
                            semail  = _mailService.SendRandomPasswordEmail(msg, Email, subject);
                        }
                    }
                    if (semail == GlobalConst.Message.EmailSentSuccessfully)
                    {
                        _client.IsEmailSent = true;
                        _client.ClientID    = _clientService.AddClient(Mapper.Map <NEPService.ClientService.Client>(_client));


                        string folderPath = Server.MapPath(GlobalConst.FolderName.Storage);

                        if (!Directory.Exists(folderPath))
                        {
                            Directory.CreateDirectory(folderPath + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _client.OrganizationID + GlobalConst.ConstantChar.DoubleBackSlash + _client.ClientID);
                        }
                        else
                        {
                            string path = folderPath + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _client.OrganizationID + GlobalConst.ConstantChar.DoubleBackSlash + _client.ClientID;
                            Directory.CreateDirectory(path);
                        }
                        return(Json(GlobalConst.Message.AddSucessfully, GlobalConst.Message.text_html));
                    }
                    else
                    {
                        return(Json(semail, GlobalConst.Message.text_html));
                    }
                }
                else
                {
                    return(Json(GlobalConst.Message.EmailExist, GlobalConst.Message.text_html));
                }
            }
            else
            {
                string subject;
                string Email;
                string msg;

                string folderPath = Server.MapPath(GlobalConst.FolderName.Storage);
                if (_client.IsEmailSent != true)
                {
                    if (_client.IsActive == true && _client.IsApproved == true)
                    {
                        _client.TempPassword = _encryptionService.GenratePassword(7);
                        _client.Password     = _encryptionService.HashPassword(_client.TempPassword);
                        Email   = _client.EmailID;
                        subject = "Client Registration & New Password";
                        msg     = @"   <p>Hi " + _client.FirstName + " " + _client.LastName + @",</p>
                            <p>Your password is this : " + _client.TempPassword + @"</p>
                            <p>Thanks!</p>";
                        _mailService.SendRandomPasswordEmail(msg, Email, subject);
                        _client.IsEmailSent = true;
                    }
                }

                var clientModel = _clientService.GetClientByID(_client.ClientID);
                _client.Password  = clientModel.Password;
                _client.ApproveOn = clientModel.ApproveOn;
                _client.ClientID  = _clientService.UpdateClient(Mapper.Map <NEPService.ClientService.Client>(_client));
                return(Json(GlobalConst.Message.UpdateSucessfully));
            }
        }